Re: using helpers from gems

125 views
Skip to first unread message

Nick Sutterer

unread,
May 13, 2014, 6:14:44 PM5/13/14
to cells-an...@googlegroups.com
This is exactly how it works! When using a view model cell, you don't need the helper call anymore, a simple include ...Helper will do!

Nick


On Wed, May 14, 2014 at 2:16 AM, John Lane <goo...@jelmail.com> wrote:
Hi Nick, I hope you don't mind another question...?

I added a gem (font-awesome-rails) to my app that provides some helpers (I know how you feel about helpers!) but they aren't automatically available to widget views (they work find in controller views so they are definately there). I have it working by doing the below in my widget controller

include FontAwesome::Rails::IconHelper
helper_method :fa_icon, :fa_stacked_icon

This makes the helper "fa_icon" and "fa_stacked_icon" usable from the widget's view.

I just thought I'd ask whether this is correct or if I am missing something.

Cheers,
John

--
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "Cells and Apotomo" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an cells-and-apot...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.

John (Google)

unread,
May 14, 2014, 11:07:41 AM5/14/14
to cells-an...@googlegroups.com
Thanks, but if I remove the line "helper_method :fa_icon, :fa_stacked_icon", leaving just the "include FontAwesome::Rails::IconHelper", then I get an error

undefined method `fa_icon' for #<#<Class:0x007f7c44b39710>:0x007f7c44ed8998>
app/widgets/items/item/new.html.erb:11:in `block (3 levels) in _app_widgets_items_item_new_html_erb___3916006560309589765_70085854558640'
app/widgets/items/item/new.html.erb:8:in `times'
app/widgets/items/item/new.html.erb:8:in `block (2 levels) in _app_widgets_items_item_new_html_erb___3916006560309589765_70085854558640'
app/widgets/items/item/new.html.erb:2:in `block in _app_widgets_items_item_new_html_erb___3916006560309589765_70085854558640'
app/widgets/items/item/new.html.erb:1:in `_app_widgets_items_item_new_html_erb___3916006560309589765_70085854558640'
app/widgets/items/item_widget.rb:22:in `new'
app/views/items/new.html.erb:1:in `_app_views_items_new_html_erb___2021057299011525257_70085854746000'
J

Nick Sutterer

unread,
May 14, 2014, 6:15:46 PM5/14/14
to cells-an...@googlegroups.com
Yes, because you're not using a view model Cell: https://github.com/apotonick/cells#view-models

Kevin Incorvia

unread,
Sep 18, 2014, 2:05:05 PM9/18/14
to cells-an...@googlegroups.com
I too experienced this.. I needed to add helper_method for it to work... I am using Cell::ViewModel.   I don't know why as the documentation and as Nick point out you shouldn't need to .. but without it I get undefined method errors...

Nick Sutterer

unread,
Sep 18, 2014, 6:19:58 PM9/18/14
to cells-an...@googlegroups.com
In Cells 4.0, everything is a view model, the concept of ::helper doesn't exist anymore (and that's damn awesome!!!!). If you need a helper, just include it into the class itself, it's then available in the instance and the view (as it's the same context). Does that help?
Reply all
Reply to author
Forward
0 new messages