twitter-bootstrap-rails icon indicating copy to clipboard operation
twitter-bootstrap-rails copied to clipboard

devise and simple_form conflict

Open caeg0n opened this issue 10 years ago • 20 comments

with simple_form show me a error in line <%= error_span(@information[:unity]) %> with description: undefined local variable or method `object' for #<#Class:0x000000061ac740:0x000000064307a0> on partial view file _form.html.erb

caeg0n avatar Oct 04 '14 17:10 caeg0n

Can you post how you are using form_for please

toadkicker avatar Oct 04 '14 17:10 toadkicker

this a complete form generated by scaffold i run the bootstrap:layout and bootstrap:themed too

<%= simple_form_for @information, :html => { :class => 'form-horizontal' } do |f| %> <%= f.input :unity %> <%= error_span(@information[:unity]) %> <%= f.input :slogan %> <%= error_span(@information[:slogan]) %> <%= f.input :address %> <%= error_span(@information[:address]) %> <%= f.input :owner %> <%= error_span(@information[:owner]) %> <%= f.input :phone %> <%= error_span(@information[:phone]) %> <%= f.input :mail %> <%= error_span(@information[:mail]) %>

<%= f.button :submit, :class => 'btn-primary' %> <%= link_to t('.cancel', :default => t("helpers.links.cancel")), information_index_path, :class => 'btn btn-default' %> <% end %>

caeg0n avatar Oct 04 '14 20:10 caeg0n

You can drop using the instance variable on error span and use only the attribute, or pull the develop branch.

error_span :unity

toadkicker avatar Oct 05 '14 06:10 toadkicker

right toadkicker but i think that a gem can't generate wrong code. i having too many problems with this gem. i give up to use it with the gems Devise and Simple Form.

caeg0n avatar Oct 05 '14 14:10 caeg0n

I've forked this project and on https://github.com/toadkicker/railsstrap am not having this issue. Don't give up!

toadkicker avatar Oct 05 '14 14:10 toadkicker

@K43G0N @toadkicker I am also facing this issue.

devise (3.4.1) simple_form (3.1.0) twitter-bootstrap-rails (3.2.1)

sachin87 avatar Jan 31 '15 06:01 sachin87

solved in toadkicker/railsstrap fork.

caeg0n avatar Jan 31 '15 12:01 caeg0n

@K43G0N but i am not using railsstrap.

sachin87 avatar Feb 02 '15 06:02 sachin87

For anyone who cares, I've managed to fix the problem with this on an initializer:

if defined?(SimpleForm::FormBuilder)
  SimpleForm::FormBuilder.send(:include, FormErrorsHelper)
end

The helper is included into the rails' form builder and simple_form extends it, so I'm not sure why this happens (maybe depends on the order of the gem loading?), but this ensures the form builder simple form uses has the method

Draiken avatar Nov 03 '15 19:11 Draiken

@Draiken where did you put this code, I can't get it to work :/

ellesgaard avatar Dec 01 '15 08:12 ellesgaard

I've put it into an initializer. Twitter bootstrap rails adds the error helpers to the Rails' FormBuilder, but SimpleForm uses his own form builder on top of it, creating the conflict.

If this doesn't work, I'm not sure what else could be done, other than taking a look at both gems and producing a real fix

Draiken avatar Dec 01 '15 08:12 Draiken

The initializer don't work for me =/ Why not just generate the form in the new way, like f.error_span :unity ?

gustavobap avatar Dec 18 '15 01:12 gustavobap

Using f.error_span generates undefined method without explicitly including the form helpers in simple form's FormBuilder

Draiken avatar Dec 18 '15 09:12 Draiken

You mean f.error_span only works with simple_form ? It works for me using devise and simple_form and no change in intializers. I installed the gem this way: gem "twitter-bootstrap-rails", :git => "https://github.com/seyhunak/twitter-bootstrap-rails.git", :branch => "master"

gustavobap avatar Dec 18 '15 19:12 gustavobap

I also have this problem.

I'm using:

devise (3.5.3) simple_form (3.2.0) twitter-bootstrap-rails (3.2.2)

what can I do?

thank you in advance for any help...

epineda avatar Jan 09 '16 00:01 epineda

Only downgrade to 'twitter-bootstrap-rails', '3.2.0' helps.

BabichSA avatar Jan 18 '16 19:01 BabichSA

I also have this problem, and downgrade is worked for me. Thank @BabichSA

luss613 avatar Jan 20 '16 04:01 luss613

Thank @BabichSA it worked for me I am very very very grateful.

BarbaraTieko avatar Mar 16 '16 02:03 BarbaraTieko

It helps, but not for rails 5:

    twitter-bootstrap-rails (= 3.2.0) was resolved to 3.2.0, which depends on
      railties (~> 4.1)

apsheronets avatar Aug 22 '16 07:08 apsheronets

When I've generated was like this:

= error_span(@information[:slogan])

And I changed to:

= f.error_span(:slogan)

And worked!

Rails 5, devise + simple_form + bootstrap templates

brunoocasali avatar Nov 01 '16 03:11 brunoocasali