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