Problem with select_date

In my form I have these items:

<%= select_year Date.today,
:start_year => Schoolyear.get_startdate.year,
:end_year => Schoolyear.get_enddate.year %>
<%= select_month Date.today.month %>

No matter what I do, in my controller I can’t seem to access the
selected year and
month.

I have tried params[:month].to_s and also params[:date][:month], plus
anything I could come up with, but so far no success.

Does anybody knows what I am doing wrong?

oom tuinstoel wrote:

In my form I have these items:

<%= select_year Date.today,
:start_year => Schoolyear.get_startdate.year,
:end_year => Schoolyear.get_enddate.year %>
<%= select_month Date.today.month %>

No matter what I do, in my controller I can’t seem to access the
selected year and
month.

I have tried params[:month].to_s and also params[:date][:month], plus
anything I could come up with, but so far no success.

Does anybody knows what I am doing wrong?

Have you tried:

<%=date_select(“myobject”,“start_date”)%>

If there is invalid input (Feb 30th) you’ll need to catch that by doing
this in your controller:

  begin
    @myobject = MyObject.new(@params[:myobject])
    # Catch the exception from AR::Base
  rescue ActiveRecord::MultiparameterAssignmentErrors => ex
    # Iterarate over the exceptions and remove the invalid field
    # components from the input
    ex.errors.each { |err|
      @params[:myobject].delete_if { |key, value| key =~ 

/^#{err.attribute}/ }
}
# Recreate the Model with the bad input fields removed
@myobject = MyObject.new(@params[:myobject])
end

if the date field is required, just put validates_presence_of
:start_date in the model and it will catch the invalid input.

Was this any help?

Andrew S. wrote:

Was this any help?

No Andrew, sorry. I guess I didn’t state my problem correctly. I have a
view where I want the user to select a year and a month, and in my
controller I will do some work for the chosen year and month. The year
and month however are not in the db. So I read in AWDWR that I then have
to use select_year and select_month. The view is working, but I can’t
get to the variables. Thanks anyway.