6

I have been struggling with this one for days and can't seem to figure out what's wrong. I'm attempting to allow polymorphic file attachments to a model Item, which belongs to model Location. My routes are defined as:

resources :locations do
  resources :items
    post :sort
end

resources :items do
  resources :assets #model for attachments
end

I followed a tutorial about doing exactly this with carrierwave and nested_form. After setting everything up, however, I get the following error when requesting the New action for the Item model: wrong number of arguments (4 for 3). It tells me the error is occurring at line 7 of this view:

<%= nested_form_for [@location, @item], :html => { :multipart => true } do |f| %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>

  <%= f.fields_for :assets do |a_form|  %> ### LINE 7 ####
    <p>
      <%= a_form.label :file %><br />
      <%= a_form.file_field :file %>
      <%= a_form.hidden_field :file_cache %>
    </p>
    <%= a_form.link_to_remove "Remove this attachment" %>
  <% end %>

  <%= f.link_to_add "Add attachment", :assets %>
  <p><%= f.submit %></p>
 <% end %>

If I don't use the nested_form gem and start out the view with a normal form_for, I get no errors and am able to successfully attach a single file to the Item. I can try and proceed without the gem, but (as far as I understand) nested_form will automate some of the functionality like removing the files and generating ajax to add new attachments.

I was just wondering if anyone has run into this error or knows what mistake I'm making that's causing problems with nested_form? I understand what the error means, just not sure where/why the extra argument is being thrown in. I greatly appreciate any insight you can provide!

FYI my dev setup: rails (3.1.0, 3.0.10), nested_form (0.1.1), carrierwave (0.5.7)

Denny
  • 319
  • 2
  • 8

1 Answers1

15

In order to get nested_form working with rails 3.1, I had to pull the latest from github rather than using what's in the gem. In my Gemfile:

gem "nested_form", :git => "git://github.com/ryanb/nested_form.git"
marina
  • 406
  • 3
  • 4
  • THANK YOU! I can't believe that's all it was. I had seen [this post](http://stackoverflow.com/questions/6655674/rails-simple-nested-form-for-fields-for-wrong-number-of-arguments) where the comment mentioned the version being out of date... however my version numbers matched and the post was from July so I assumed that rubygems had been updated and I never gave it a second thought. Thanks again, appreciate your time. You rule :) – Denny Sep 24 '11 at 19:16