0
votes

I'm trying to use Rails date helpers with a form. However, I only want to get the year. I got the form code below from simple_form gem https://github.com/plataformatec/simple_form. The discard_day and discard_month prevent the month and day select box from showing. However, when I submit the form, I'm getting this multiparameter error

2 error(s) on assignment of multiparameter attributes
"start(1i)"=>"2013",
 "start(2i)"=>"4",
 "start(3i)"=>"23",
 "end(1i)"=>"2011",
 "end(2i)"=>"4",
 "end(3i)"=>"23",

It appears Rails is just substituting the current day and month since none was entered in the form.

I'm wondering if there's a way to prevent Rails from including the current day and month, or am I supposed to deal with it in the controller. Right now, the create action looks like this

   def create
    @employment = current_user.employments.build(params[:employment])
    if @employment.save
    ....

If I can't stop Rails from including the current day and month, then what would I do in the controller?

  <%= f.input :start, as: :date, start_year: Date.today.year - 90,  
                              end_year: Date.today.year, discard_day: true, discard_month: true %>


   <%= f.input :end, as: :date, end_year: Date.today.year - 90,
                              end_year: Date.today.year, discard_day: true, discard_month: true %>
1

1 Answers

1
votes

What is your data type for the start and end columns? If you are just storing a year, you can set them to an integer type instead of a date, and use <%= f.input :start, collection: (Date.today.year - 90)..(Date.today.year) %>.