Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherit from multiple controllers.

Im using a Rails engine as a cms. It all works fine. Im adding devise to this.

My generated devise controllers inherit from Devise::SessionsController. But there are some filters that are run from another controller in the engine that wont run in this case. A lot of the site relies on these filters being run. Of course I could just duplicate them, but thats bad juju.

So my Question is: How can I make one controller run the filters from another? I would prefer not to edit either of the gems.

like image 691
DickieBoy Avatar asked Aug 28 '26 20:08

DickieBoy


2 Answers

Multiple inheritance is not supported in Ruby. I think extracting the filters into a module and mixing them in would be the cleanest solution.

See for example: http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html

like image 117
Wukerplank Avatar answered Aug 31 '26 13:08

Wukerplank


There is another option available for Devise: config.parent_controller. It defaults to ApplicationController but can be changed to something else. In my case (a Rails API) I use ApiController. In config/initializers/devise.rb:

Devise.setup do |config| # ... other configuration options config.parent_controller = 'ApiController' end

like image 21
Jeremy Lewis Avatar answered Aug 31 '26 13:08

Jeremy Lewis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!