Im stumped. I followed Ryan Bates screencast 73 and had this working
the other day for an assets model. Today im trying to implement the
same thing for a case_study model that belongs_to :services.
MODEL: CaseStudy
belongs_to :services
MODEL: Services
has_many :case_studies, :dependent => :destroy
def case_studies=(case_studies)
case_studies.each do |attribute|
case_studies.build(attribute)
end
end
CONTROLLER: new method
@service.case_studies.build
in my _form partial for services
<% form_for(@service, :html => {:multipart => true}) do |f| %>
...
(this is the nested part)
<% for case_study in @service.case_studies %>
<% fields_for "service[case_studies][]", case_study do |
case_study_form|%>
<p>
<%= case_study_form.label :title %><br />
<%= case_study_form.text_field :title %>
</p>
<p>
<%= case_study_form.label :description %><br />
<%= case_study_form.text_area :description, :rows =>
5, :cols => 29 %>
</p>
<p>
<%= case_study_form.label :permalink %><br />
<%= case_study_form.text_field :permalink %>
</p>
<p>
<%= case_study_form.label :keywords %><br />
<%= case_study_form.text_field :keywords %>
</p>
<p>
<%= case_study_form.label "Add Case Study" %><br
/>
<%= case_study_form.file_field :attachment, :size => 16 %>
</p>
<% end %>
<% end %>
...
<% end %>
This is where its weird. I can raise the params and it shows the hash,
but it adds a [-] hash to the case_studies hash.
all the form fields are named service[case_studies][-][attr etc...]
when i view the source
any help here?
Thanks in advance
Bob