I have followed Ryan Bates tutorial on nested models. Several of my nested models have dates associated with them. In my migrations, they are actually the type "Date."
Some things I have tried and problems I've run into
Any ideas or hints would be helpful.
Edit: before_save seems to be more promising but for some reason, the value is nil coming into before save but is visible in the log dump.
Edit 2: Interestingly, this only seems to be a problem on 'update', not on 'create'.
I'd seriously hope that this works for date_select as well:
http://jeffperrin.com/2009/06/04/rails-nested-forms-and-collection_select/
This is the solution:
<% new_or_existing = task.new_record? ? 'new' : 'existing' %>
<% prefix = "project[#{new_or_existing}_task_attributes][]" %>
<% fields_for prefix, task do |t| -%>
<%= t.date_select(:start_date, :index => task.id || nil) %>
<% end -%>
Here's the explanation of why it works:
http://agilerails.wordpress.com/2009/03/11/date_select-time_select-doesnt-work-with-auto_prefix-object/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With