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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:41:45+00:00 2026-06-08T16:41:45+00:00

I am learning rails via Hartl’s tutorial, but I can get chapter 9.2.3 Link

  • 0

I am learning rails via Hartl’s tutorial, but I can get chapter 9.2.3 Link to work

Everything before this section was working perfectly before this section, but after getting here, if I access /users/1/edit and login with a different or same user, it redirects back to the user page and not to the edit page.

sessions helper:

def redirect_back_or(default)
    redirect_to(session[:return_to] || default)
    session.delete(:return_to)
end

def store_location
    session[:return_to] = request.fullpath
end

users controller methods for before_filter

private

def signed_in_user
  unless signed_in?
    store_location
    redirect_to signin_path, notice: "Please sign in."
  end
end

def correct_user
  @user = User.find(params[:id])
  redirect_to(root_path) unless current_user?(@user)
end

before filters in user controller

before_filter :signed_in_user,only:[:edit,:update,:index]
before_filter :correct_user, only:[:edit,:update]

My code so far Github

  • 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-06-08T16:41:46+00:00Added an answer on June 8, 2026 at 4:41 pm

    You missed calling redirect_back_or user instead of redirect_to in SessionsController create:

      def create
        user = User.find_by_email(params[:session][:email])
          if user && user.authenticate(params[:session][:password])
            sign_in user
            redirect_back_or user
          else
            flash.now[:error] = 'Invalid email/password combination' # Not quite right!
            render 'new'
          end
      end
    

    I found out by adding the session to the debug info at the bottom of the page, and the return_to was still there after successful login:

    {"session_id"=>"4dcc1baaf651aaab953026902b32f805", "_csrf_token"=>"0YkP+yd/DDuInX4kIBkjwbzxV1GK0oYBDAXEiWnHLGs=", "return_to"=>"/users/1/edit"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to rails and still learning the ropes via railstutorial, but the book
While learning Rails, I found this example in the Sam Ruby's book: app/controllers/line_items_controller.rb def
I'm learning rails and I've come across a little quirk that I can't seem
I'm currently reading Learning Rails 3. I'm working on an example where you can
I've been learning Rails but routes continues to confuse the heck out of me.
I am learning rails from rails tutorial. I got a problem in the Section
Possible Duplicate: Can't convert String into integer in ruby/ruby-on-rails I'm running through a tutorial
I'm learning rails and I'm just trying to get the basics down. I just
I am learning rails by following the Rails Tutorial under Ubuntu. I have been
I'm following a tutorial (the learning rails podcast) and need to change the following

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.