stouset / twitter_bootstrap_form_for

A Rails FormBuilder DSL for generating Twitter Bootstrap forms
https://github.com/stouset/twitter_bootstrap_form_for
MIT License
409 stars 110 forks source link

twitter_bootstrap_fields_for not working #38

Open amisarca opened 12 years ago

amisarca commented 12 years ago

When trying to do twitter_bootstrap_fields_for, and then call new_form.inputs, this error is shown "undefined method `inputs' for #<ActionView::Helpers::FormBuilder"

amisarca commented 12 years ago

I discovered the issue. The signature of the fields_for method is

def fields_for(record_name, record_object = nil, options = {}, &block)

But the call in form_helpers.rb is

send method, record, *(args << options), &block

So, the options hash, which contains the :builder key that defines the builder, is sent as the second parameter, not the third. And this is why the builder does not change.

stouset commented 12 years ago

The fields_for method in TwitterBootstrapFormFor::FormHelpers is defined as

define_method "twitter_bootstrap_#{method}" do |record, *args, &block|

The call works as expected: the record is passed as the first parameter, and the options hash is pulled out of *args, modified, and re-added. Can you please make a minimal example case of this bug?

amisarca commented 12 years ago
<%= twitter_bootstrap_fields_for @user do |user_form| %>
  <%= user_form.inputs 'Sign Up', :class => 'sign_up' do %>

And the error is

undefined method `inputs' for #<ActionView::Helpers::FormBuilder:0xa969c68>

Also

<%= twitter_bootstrap_fields_for @user, nil do |user_form| %>
  <%= user_form.inputs 'Sign Up', :class => 'sign_up' do %>

works fine. So, if the second argument is omitted, the options argument is sent as the second argument, and it is not recognized. I think that before calling the send method, it should be checked if the method is field_for, and the number of arguments is 0, and in this case a nil argument should be added