Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Ruby refinements in Rails views?

I have a Rails 4 project using Ruby 2.0. I've defined some refinements. Putting

<% using MyRefinements %>

at the top of the view files causes the error "undefined method 'using'".

When I add:

using MyRefinements

At the top of my controller (above the class declaration), I can successfully use the refinement in the controller, but I get an 'undefined method' error if I try to use it in the view.

Thanks!

like image 454
Brad Urani Avatar asked Mar 17 '14 19:03

Brad Urani


Video Answer


1 Answers

Unfortunately, this does not seem possible. For posterity, I'm documenting the things I tried that didn't work:

In the view:

<% using MyRefinements %>

In the controller (each tried separately):

using MyRefinements
helper :MyRefinements
helper_method :MyRefinements
helper { using MyRefinements }

In the helper:

using MyRefinements

Note that refinements become available in the controller and in the helper, but never in the view.

Too bad.

like image 84
Dan Kohn Avatar answered Oct 10 '22 15:10

Dan Kohn