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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:35:04+00:00 2026-05-30T13:35:04+00:00

I am trying to override a the redirect_to method to add an additional param

  • 0

I am trying to override a the redirect_to method to add an additional param to the get requests (if thats present)

The redirect_to method is here

module ActionController
...................

  module Redirecting
    extend ActiveSupport::Concern
    include AbstractController::Logger
    ...........................

    def redirect_to(options = {}, response_status = {}) #:doc:
      ............................
      self.status        = _extract_redirect_to_status(options, response_status)
      self.location      = _compute_redirect_to_location(options)
      self.response_body = "<html><body>You are being <a href=\"#    {ERB::Util.h(location)}\">redirected</a>.</body></html>"
    end

  end

end

Here is how I am trying to override

module ActionController

    module Redirecting
      def redirect_to(options = {}, response_status = {})

        if options
          if options.is_a?(Hash)
            options["custom_param"] = @custom_param
          else
            if options.include? "?" 
              options = options + "&custom_param=true"
            else
              options = options + "?custom_param=true"
            end 
          end
        end 

        super 

      end

  end

end 

I am apparently doing it wrong, and the super method call fails to work the way I wanted it. Hope someone could help.

  • 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-30T13:35:05+00:00Added an answer on May 30, 2026 at 1:35 pm

    I believe the problem here is that you are redefining the redirect_to method, not defining in a new place. super cannot call the original because it no longer exists.

    The method you are looking for is alias_method_chain

    module ActionController
      module Redirecting
    
        alias_method_chain :redirect_to, :extra_option
    
        def redirect_to_with_extra_option(options = {}, response_status = {})
    
          if options
            ...
          end
    
          redirect_to_without_extra_option(options, response_status)
        end
      end
    end
    

    Though, I think the more Rails friendly way would be to override redirect_to in your ApplicationController

    class ApplicationController
      ....
      protected
        def redirect_to(...)
          if options
            ....
          end
          super
        end
    end
    

    The benefits to this approach are that you aren’t patching rails and the application specific param is now set in your application controller.

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

Sidebar

Related Questions

Am trying to override get() method in my view as : broadcast = Broadcast.objects.get(request,
I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so
I'm trying to figure out how I can override the auth_views.logout method. Normally I
I'm trying to override equals method for a parameterized class. @Override public boolean equals(Object
I have been trying to override the database method of the loader class (CI_Loader).
I am trying to override the load() (abstract) method in org.primefaces.model.LazyDataModel class (from Primefaces
I am trying to override equals method in Java. I have a class People
I am trying to override save in the modelform to add the current user
I am trying to override an active resource method like explained in this question
Trying to override a tostring in one of my classes. return string.Format(@ name =

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.