tomkra / font_awesome5_rails

font_awesome_5_rails is font awesome 5 gem bundled for rails asset pipeline
https://fontawesome.com/
MIT License
158 stars 25 forks source link

undefined method `fa_icon' for Class #53

Open Rockster160 opened 4 years ago

Rockster160 commented 4 years ago

Getting an undefined method when trying to call the helper using version 1.0.0 on Rails 5.2.2.1.

Assets are being loaded as expected as I can manually include the <i class="fab fa-accessible-icon"></i> tags, however, when trying to use the helper method- I get an undefined version from above.

Bundle install and restarting server does not solve this issue.

tomkra commented 4 years ago

Hello @Rockster160 , did you resolved your issue? I have no problem with calling fa_icon helper method. Methods provided by this gem will be accessible only in your views and representers. If you want to call it in models or controllers, you will have to include it manually.

Rockster160 commented 4 years ago

I was calling the methods within views and never got it working. I eventually defined my own helper that generates the html.

It's possible it's related to the fact that the views were in a namespaced file? So instead of views/users/index it was in views/v2/users/index - I don't see why that would cause an issue, but that's the only thing I can see that's different.

tomkra commented 4 years ago

No that shouldn't cause any problems. I use this gem in many projects and everything works as expected even in namespaced views. Maybe if you use some gem, that have dependency on older font-awesome gem this could cause problem (but you shouldn't get undefined method).

Try call fa5_icon instead of fa_icon in your view and see if it resolve your issue.

Rockster160 commented 4 years ago

fa5_icon has the same issue. When called from a view, an error is raised:

NoMethodError at /.../...
undefined method `fa5_icon' for #<#<Class:0x00007fcefc01b0f8>:0x00007fcefc02a738>
AFlowOfCode commented 3 years ago

I noticed this on a mailer template, but given the style requirements for an email it doesn't really make sense to use it there.

dedemenezes commented 2 years ago

Any solutions on this?

undefined method `fa_icon' for #<ActionView::Base:0x000000000112b0>

rails version 6.1.4.1 ruby version 2.7.4p191 (2021-07-07 revision a21a3b7d23)