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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:36:14+00:00 2026-05-13T23:36:14+00:00

My Rails 2.3 application has a User model and the usual controller actions. The

  • 0

My Rails 2.3 application has a User model and the usual controller actions. The edit form can be reached two ways: when a user edits his own profile from the home page, or when an admin user edits someone else’s profile from users collection.

What I’d like to do is have the update action redirect back to the referred of the edit action, not the update action. If I do a simple redirect_to(:back) within update, it goes back to the edit form — not good.

One solution is to forget entirely about referrers and redirect based on the current_user and the updated user: if they’re the same, go back to the home page, else go to the users collection page. This will break if I ever add a third path to the edit form. It’s doubtful I’ll ever do this but I’d prefer a solution that’s not so brittle.

Another solution is to store the referrer of edit form in a hidden field and then redirect to this value from inside the update action. This doesn’t feel quite right, though I can’t explain why.

Are there any better approaches? Or, should I stop worrying and go with one of the two I’ve mentioned?

  • 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-13T23:36:14+00:00Added an answer on May 13, 2026 at 11:36 pm

    You can memorize the url in the session. This is how I implemented this feature in my application.

    Add these methods to your ApplicationController

    def store_location location=nil
        session[:return_to] = location || request.request_uri
    end
    
    def redirect_back_or_default(default)
        redirect_to(session[:return_to] || default)
        session[:return_to] = nil
    end
    
    def http_referrer
      http_referer, request_path  = request.env["HTTP_REFERER"], 
                                    request.env["REQUEST_PATH"]
      return nil  unless (http_referer and request_path and 
                          http_referer =~ Regexp.new("^#{SITE_ROOT}") and
                          http_referer != (SITE_ROOT + request_path))
      return http_referer    
    end
    

    In UserController edit/new action store the referrer.

    before_filter :store_location, :only => [:new, :edit]
    
    def store_location
      super http_referrer
    end
    

    In UserController create/update action return and reset referrer.

    def create
      if @user.save
        flash[:notice] = "Successfully created the user."
        redirect_back_or_default root_url
      else
        render :action => 'new'
      end
    end    
    
    def update
      if @user.save
        flash[:notice] = "Successfully created the user."
        redirect_back_or_default root_url
      else
        render :action => 'new'
      end
    end    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails application where each user has a separate database. (taking Joel
I have a Rails application that unfortunately after a request to a controller, has
Got a rails application that has a form (new action) with a select with
After our Ruby on Rails application has run for a while, it starts throwing
I have a Rails project which has a Postgres database for the actual application
I'm using Clearance for authentication in my Rails application. The Clearance::User mixin adds a
I am building a Rails application which allows a user to create an object
Rails 3 newbie here.... I'm looking to build an application that limits a user's
I have a rails application which is still showing the cachebusting numeric string at
I have a rails application running on a Linux server. I would like to

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.