Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twitter_bootstrap_fields_for not working #38

Open
amisarca opened this issue Jan 14, 2012 · 3 comments
Open

twitter_bootstrap_fields_for not working #38

amisarca opened this issue Jan 14, 2012 · 3 comments

Comments

@amisarca
Copy link

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
Copy link
Author

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
Copy link
Owner

stouset commented Jan 14, 2012

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants