[LRUG] Parameterising a Rails 3 controller mixin

Graham Ashton graham at effectif.com
Tue Oct 4 06:27:38 PDT 2011


On 4 Oct 2011, at 13:27, Andrew Stewart wrote:

> I have a Rails 3 engine which mixes a module into ActionController::Base.  The module provides helper methods in the controller such as `current_foo`.
> 
> Now, however, I want to parameterise those methods based on a configuration value.

Another "not really an answer" style suggestion from me…

If you want to configure an engine, you could allow the user of the engine to do it in an initializer.

Rails::Engine inherits from Rails::Railtie. Have a look at the Configuration section on here:

http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html

It might not really fit what you're trying to do, but I thought it worth mentioning just in case.

To test it you could skip the config setting when Rails.env is test and call the config block inside your test file.


More information about the Chat mailing list