Jirico
Jirico

Reputation: 1262

How do I use Ruby refinements inside Rails Controller/Action?

If I try outside the controller it works:

using ParamsExtension
class ApplicationController

If I try inside the controller or an action it does not work:

class ApplicationController
using ParamsExtension

It throws 'undefined method `using'.

I read this article and the author is using it inside a class: timelessrepo.com/refinements-in-ruby

Upvotes: 1

Views: 1547

Answers (2)

Patrick C
Patrick C

Reputation: 186

Based on this article, refinements within classes are only available on 2.3 and up.

Upvotes: 2

Keith
Keith

Reputation: 696

I read the following from the documentation:

You may only activate refinements at top-level, not inside any class, module or method scope. You may activate refinements in a string passed to Kernel#eval that is evaluated at top-level. Refinements are active until the end of the file or the end of the eval string, respectively.

http://www.ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html

Upvotes: 1

Related Questions