Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:53:06+00:00 2026-05-16T07:53:06+00:00

I am upgrading my Rails plugin to be an engine that works with the

  • 0

I am upgrading my Rails plugin to be an engine that works with the latest 3.0RC1 release and I’m having a bit of trouble figuring out the best (and most correct) way to extend ActionController. I’ve seen this post by DHH and this question here on SO, but my question is more about how to properly call code within the ActionController.

For instance, I need to call the following within my engine’s controller:

class ApplicationController < ActionController::Base
  helper :all

  before_filter :require_one_user
  after_filter :store_location

  private
    def require_one_user
      # Code goes here
    end

    def store_location
      # Code goes here
    end
end

I know how to properly include my two private functions, but I can’t find a way to get it to properly call helper, before_filter and after_filter.

I would greatly appreciate some links or a way to make this work. I have tried naming my controller something other than ApplicationController and having the real ApplicationController extend it, but that doesn’t seem to work either. I’m really up for any solution that makes the life of the engine user as easy as possible. Ideally, they wouldn’t have to extend my class, but they’d have all of the functionality built into their own ApplicationController.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:53:06+00:00Added an answer on May 16, 2026 at 7:53 am

    You may also want to look into the initializers inside your engine subclass, so you don’t have to include view helpers inside your controller class. And this will give you control over the load order of these modules.

    Here is what I have been using:

    
    module MyEngine  
      class Engine < Rails::Engine  
        initializer 'my_engine.helper' do |app|  
          ActionView::Base.send :include, MyEngineHelper  
        end  
    
        initializer 'my_engine.controller' do |app|  
          ActiveSupport.on_load(:action_controller) do  
             include MyEngineActionControllerExtension  
          end
        end
      end
    end
    
    

    Also, another option for the action controller extension is using a mixin module. This will let you use the before_filter, after_filter, etc..

    
    module MyEngineActionControllerExtension
      def self.included(base)
        base.send(:include, InstanceMethods) 
        base.before_filter :my_method_1
        base.after_filter :my_method_2
      end
    
      module InstanceMethods
       #...........
      end
    end
    
    

    One other thing… if you create the default rails directories at the top level of your gem, you don’t have to worry about requiring the helpers or controllers. Your engine subclass has access to them. So I add my application controller and application helper extensions here:

    /myengine/app/helpers/myengine_application_helper_extension.rb
    /myengine/app/controllers/my_engine_action_controller_extension.rb
    

    I like this setup because it looks similar to the application_controller and application_helper in your rails app. Again, this is just personal preference, but I try to keep anything that is directly rails related, such as controllers, helpers and models inside /my_engine/app and anything that is related to the plugin in general inside /my_engine/lib

    Check out this tutorial by Jose Valim for more info on initializers:
    https://gist.github.com/e139fa787aa882c0aa9c (engine_name is deprecated now, but most of this doc seems up-to-date)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.