hi i'm having trouble defining association has_many in order accepts_nested_attributes_for work.
def work_days work_days = workday.user_id_equals(self.user_id).company_id_equals(self.company_id) end accepts_nested_attributes_for :work_days
what solution? there anyway can association?
-- rails 3.0.7
firstly write work_days
method this:
def work_days workday.where(:user_id => user_id, :company_id => company_id) end
next, accepts_nested_attributes_for
real associations, , define method this:
def work_days=(work_day_params) # iterate on work_day_params , define new work day objects required end
(i may have method name wrong)
in form have this:
<% f.fields_for :work_days |work_day| %> <%= render :partial => "work_days/fields", :locals => { :f => work_day } %> <% end %>
in partial have whatever necessary work day. once form submitted params should sent through controller params[:nest][:work_days]
, work_days=
method defined on model, should accept them , create them accepts_nested_attributes_for
does.
Comments
Post a Comment