Search code examples
ruby-on-rails-3ruby-on-rails-3.2formbuilder

Formbuilder generated was not right for the render partial in rails 3.2.8 ajax call


We using the following code to pass a formbuilder to a render partial in new.js.erb:

  <% @f = ActionView::Helpers::FormBuilder.new(:expense, @expense, self, {}, proc {} ) %> 
  var rpt = $("<%= escape_javascript(render 'expenses/expense_for', :f => @f) %>");

The @f is the formbuilder generated for the partial. The error is:

ActionView::Template::Error (undefined method `input' for #<ActionView::Helpers::FormBuilder:0x60c6828>):
    1: <%= f.input :expense_for, :label => "栏目: ", :collection => @expense_for  %>

The partial _expense_for.html.erb is:

<%= f.input :expense_for, :label => "栏目: ", :collection => @expense_for  %>

As the error shows, the input method was not defined for f formbuilder in partial above. What could be wrong with the formbuilder passed in? Thanks.


Solution

  • The error says that ActionView::Helpers::FormBuilder has no method input. That's true as far as I know. input is a SimpleForm or Formtastic method, try with f.select (you'll need to change the arguments).