# Nested Forms adding \[-\]

**URL:** <https://www.ruby-forum.com/t/nested-forms-adding/171344>\
**Category:** Rails\
**Created:** [June 30, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/nested-forms-adding/171344 "2009-06-30T21:32:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [June 30, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/nested-forms-adding/171344/1 "2009-06-30T21:32:55Z")

</div>

Im stumped. I followed Ryan B. 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|%\>

\<%= case\_study\_form.label :title %\>  
  
\<%= case\_study\_form.text\_field :title %\>

  

\<%= case\_study\_form.label :description %\>  
  
\<%= case\_study\_form.text\_area :description, :rows =\>  
5, :cols =\> 29 %\>

  

\<%= case\_study\_form.label :permalink %\>  
  
\<%= case\_study\_form.text\_field :permalink %\>

  

\<%= case\_study\_form.label :keywords %\>  
  
\<%= case\_study\_form.text\_field :keywords %\>

  

\<%= case\_study\_form.label “Add Case Study” %\>  
  
\<%= case\_study\_form.file\_field :attachment, :size =\> 16 %\>

  
\<% 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
