10

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!

dgilperez
  • 10,716
  • 8
  • 68
  • 96
Brad Urani
  • 1,429
  • 1
  • 16
  • 29

2 Answers2

3

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.

Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
1

By using 'using' you can import class refinements from module into the current class or module definition. You can not include it in view file by 'using'. if you want to use it in view you can do following in your controller(I have not tested it):

using MyRefinements

helper :MyRefinements OR helper_method :MyRefinements

Ashutosh Tiwari
  • 984
  • 6
  • 16