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?
--
Posted via http://www.ruby-forum.com/.