I am trying to create a form which loads upon a user clicking a date in a calendar, the form then is passed the date that is clicked through the URL and the controller assigns that date to the @date variable. I then create a date_select element and assign it the @date variable. This works fine but since I do not want the user to be able to edit the date in the form I want it to be hidden.
I pass these html options to the form but it doesn’t seem to ever effect the HTML:
<%= f.date_select :date, :default => @date, :type => "hidden" %>
Am I missing something? I also tried passing it in an HTML hash :html => { :type = "hidden" } but that doesn’t work either. Even when I try something different like :class => "something" it doesn’t change the HTML. Is there something special about the date_select helper?
date_selectaccepts the optionsdiscard_day,discard_monthanddiscard_yearto do exactly what you are trying to achieve.Behind the scenes, it generates the following HTML code:
No CSS tricks, no changes in your controllers.