Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form_for wrong number of arguments (3 for 2) since upgrade to rails 3.1

this form_for used to work before I ported my application to rails 3.1

<div class="form-box" style="padding-left:1em;">
  <%
     action = @existing_mass.nil? ? "add_to_power_plant": "update_power_plant_substrate";
     submit_button_label = @existing_mass.nil? ? 'Add': 'Update';
  %>

  <%= form_for :substrate_mass, @substrate_mass, :remote => true, :url => { :action => action, :substrate_id => @substrate_mass.substrate  } do |f| %>
    <div>
      <%= f.label :quantity_per_year, "Quantity" %>
      <%= f.text_field :quantity_per_year, :size => 5, :onclick => 'this.select();', :value => @substrate_mass.quantity_per_year %>
    </div>

    <div class="actions" style="float:right;">
      <%= f.submit submit_button_label %>
    </div>
    <br/> 
  <% end %>
</div>

I have spent over 4 hours trying to figure out what's wrong ... there is definitely something I am not understanding anymore

I get the error:

wrong number of arguments (3 for 2)

Note that I am trying to update an variable that is not an activerecord object. It's just an object that is not stored in the database.

Hope someone can help.

cheers

like image 951
zabumba Avatar asked Sep 23 '11 01:09

zabumba


1 Answers

form_for only takes two arguments, the record, and options, although record may be several things, including a simple symbol, an object, or an array.

Try just dropping the first symbol and sending your object. If you model does not include ActiveModel::Naming, you may set the name via the :as option.

<%= form_for @substrate_mass, :as => 'substrate_mass', ... %>

More help may be found here:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

Or to view the source directly:
https://github.com/rails/rails/blob/v3.1.0/actionpack/lib/action_view/helpers/form_helper.rb#L353

like image 151
numbers1311407 Avatar answered Oct 28 '22 14:10

numbers1311407