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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:36:40+00:00 2026-05-27T19:36:40+00:00

I have a sessionsController and I’m trying to add a redirect_back_or method in my

  • 0

I have a sessionsController and I’m trying to add a redirect_back_or method in my sessions_helper to allow friendly forwarding.

Here is the error I get:

undefined method `redirect_back_or' for #<SessionsController:0x007f9fa1b51ec0>

I have restarted the server and can’t figure out why it’s not finding this method in my helper.

My Sessions helper code is as follows:

module SessionsHelper

  def deny_access
      store_location
      redirect_to signin_path, :notice => "Please sign in to access this page."
  end

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

  private

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

  def clear_return_to
    session[:return_to] = nil
  end

end

My sessions controller is

class SessionsController < ApplicationController

  def create
    auth = request.env["omniauth.auth"]
    user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
    session[:user_id] = user.id
    redirect_back_or user
    #redirect_to root_url, :notice => "Signed in!"
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url, :notice => "Signed out!"
  end

end
  • 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-27T19:36:40+00:00Added an answer on May 27, 2026 at 7:36 pm

    Put that method in ApplicationController:

    class ApplicationController < ActionController::Base
      private
      def redirect_back_or(default)
          redirect_to(session[:return_to] || default)
          clear_return_to
      end
    end
    

    Or include the SessionsHelper module in your controller to use the method:

    class SessionsController < ApplicationController
      include SessionsHelper
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a before_destroy filter to Devise's SessionsController. Here is what
I am trying to get the error flash to appear in the railstutorial.org sample
I have trying to solve an issue with my Spec tests and I get
I have devise 1.4.8, and I am trying to override create at Devise::SessionsController to
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you managed to get Aptana Studio debugging to work? I tried following this,
I can't seem to figure out what I am doing wrong here. I have
Have not done this before, so obviously I suck at it. Here 64 pixels
I have before_filter :method in my application_controller and I want this method to run
I have a rails app . I have created a sessionscontroller and want 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.