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

  • SEARCH
  • Home
  • 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 7004277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:10:41+00:00 2026-05-27T21:10:41+00:00

In rails, I can get the name of the current controller via controller_name and

  • 0

In rails, I can get the name of the current controller via controller_name and the current action by calling action_name. I am looking for similar runtime reflection for fetching the following:

  1. List of all controllers in the application.
  2. List of all actions in a given controller.

For example, I a Product controller which has “add” and “edit” actions. Can I pull the names of these actions programmatically to show the user what operations are supported?

I have looked at a method that calls for use of ActionController::Routing::Routes.named_routes.routes.each
but I could not get that to work. I got uninitialized constant ActionDispatch::Routing::Routes error when I used it.

If there is any good tutorial or document that can help me understand how rails reflection capabilities. I searched for it but I mostly got active record reflection related blogs. I am looking for something that lets me get information on controllers and actions/methods at run time.
Thanks,

Tabrez

  • 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-27T21:10:42+00:00Added an answer on May 27, 2026 at 9:10 pm

    The easiest way to get a list of controller classes is:

    ApplicationController.descendants
    

    However, as classes are loaded lazily, you will need to eager load all your classes before you do this. Keep in mind that this method will take time, and it will slow down your boot:

    Rails.application.eager_load!
    

    To get all the actions in a controller, use action_methods

    PostsController.action_methods
    

    This will return a Set containing a list of all of the methods in your controller that are “actions” (using the same logic Rails uses to decide whether a method is a valid action to route to).

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

Sidebar

Related Questions

I'm currently looking at a hefty Rails test suite. It's nothing I can get
I'm trying to get mysql gem installed for use on rails, using jruby, can't
I'm working on a newly configured computer, and can't seem to get rails to
Can rails handle creating a view without a controller? For example, let say I
I am looking for an upload solution for Ruby on Rails where I can
How can I get the class name from an ActiveRecord object? I have: result
How can I get the Username from an ID in Rails 3? In my
Current verbose rails path helpers I'm constantly writing code to get URLs like: link_to
Given a string with day name, i.e. Wednesday , how can I get a
A single Rails command can make lots of changes in an app - creating

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.