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 6098019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:06:33+00:00 2026-05-23T13:06:33+00:00

In appllication controller i have couple of methods that works with requested controller and

  • 0

In appllication controller i have couple of methods that works with requested controller and action name.

To follow DRY principe, i want to define share variables with those params.

class ApplicationController < ActionController::Base
   @@requested_action     = params[:action]
   @@requested_controller = params[:controller]
end

But i get error: undefined local variable or method "params" for ApplicationController:Class

Why i can’t do this and how can i achieve my goal?

  • 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-23T13:06:33+00:00Added an answer on May 23, 2026 at 1:06 pm

    I believe you already have controller_name and action_name variables defined by Rails for this purpose.

    If you want to do it by your way, you must define it as a before filter as params comes to existence only after the request is made. You can do something like this

    class ApplicationController < ActionController::Base
      before_filter :set_action_and_controller
    
      def set_action_and_controller
        @controller_name = params[:controller]
        @action_name = params[:action]
      end
    end
    

    You can access them as @controller_name and @action_name. But controller_name and action_name are already defined in Rails. You can use them directly.

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

Sidebar

Related Questions

i have this snippet that i want to access from a controller or a
I have a Rails application that unfortunately after a request to a controller, has
I have an winforms application that was built using MVC. The controller is subscribing
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have a couple of methods I'd like to share between models rather than
I have a couple of variables that need to be called in all controllers.
I'm working on an application controller for a program that is spitting text directly
My application is pretty simple: it starts up with a view controller that holds
I have a simply Class that is intended to be a simple POCO -
I have a couple of controllers on my site which are handling form data.

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.