Javix
2013-Mar-04 15:05 UTC
fields_for with accepts_nested_attributes: how to pass a value to a label
I can''t figure out how to pass a value from the following object build in the controller: class TimesheetsController < AC ... def new @timesheet = current_user.timesheets.new now = Date.today #generating 7 time entries: monday through sunday (now.beginning_of_week..now.end_of_week).step { |date| @timesheet.time_entries.build(:workdate; date) end end ... In the Timesheet model I defined accepts_nested_attributes for time_entries association: class Timesheet < AR has_many :time_entries, :dependent: :destroy accepts_nested_attributes_for :time_entries, reject_if: proc { |attr| attr[''worktime].blank? } end in the Timesheet ''new'' page: <%= form_for @timesheet do |f|%> <%= f.label :status%> <%= f.text_field :status %> <%= fields_for :time_entries do | entry_form| %> # how to display at this place the needed workdate for every time entry ? * <%= entry_form.label, value: ???? %>* <%= entry_form.text_field :worktime%> #worked time to be entered here as 0.5 or 1 day <% end%> <% end % Thanks and regards -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/fWDXeID3W4EJ. For more options, visit https://groups.google.com/groups/opt_out.
Reasonably Related Threads
- accepts_nested_attributes: undefined method 'association'_attributes
- validates presence of foreign key fails in nested form
- How to use group in nested associations
- nested forms: use validate :some_method works in update mode only
- [Rails 3.0.9] I have trouble about fields_for