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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:34:04+00:00 2026-06-04T05:34:04+00:00

For the app that I am writing, I am using simple hand made authentication

  • 0

For the app that I am writing, I am using simple hand made authentication (as described on Railscast.com). Using some code from Ryan Bates’ NiftyGenerators gem, I have an authentication model that has some useful methods for authentication. This module is included into application_controller.rb.

One of the methods that I want to use is called redirect_to_target_or_default. I know this is what I need to redirect a user to the page that they were on once they have authenticated but I don’t know where I should call this method? If someone could give me an idea on how to use this method, I would greatly appreciate it.

ControllerAuthenticaion Module Code

module ControllerAuthentication
  # Makes these methods helper methods in the controller that includes this module.
  def self.included(controller)
    controller.send :helper_method,
      :current_admin, :logged_in?,
      :redirect_to_target_or_default
  end 

  def current_admin
    @current_admin ||= Admin.find(session[:admin_id]) if session[:admin_id]
  end

  def logged_in?
    current_admin
  end

  def login_required
    unless logged_in?
      store_target_location
      redirect_to login_url,
        :alert => "You must first log in before accessing this page."
    end
  end 
  def redirect_to_target_or_default(default, *args)
    redirect_to(session[:return_to] || default, *args)
    session[:return_to] = nil
  end 
  def redirect_to_or_default(target, *args)
    redirect_to(target || default, *args)
  end 
  def store_target_location
    session[:return_to] = request.url
  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-06-04T05:34:05+00:00Added an answer on June 4, 2026 at 5:34 am

    Did you run the generator(s) within Ryan’s gem? It should have generated a SessionController (refer to link) for you with also this method in it:

    def create
      @session = Session.new(params[:session])
      if @session.save
        flash[:notice] = "Logged in successfully."
        redirect_to_target_or_default(root_url)
      else
        render :action => 'new'
      end
    end
    

    I think you can get an idea of how to use it while reading this code. 🙂

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

Sidebar

Related Questions

I am writing an app that plays some simple voices and sounds using AVAudioPlayer
I'm writing a small Django app that displays a few simple values from an
I am writing an ios app that talks to the asp.net server by using
I am writing a web app in PHP using mySQL that models an election.
I'm writing an iOS 5 app (in Xcode 4.3, using Storyboards and ARC) that
I have the following section of code in an app that I am writing:
I'm writing an app that allows you to script the buttons from a wiimote
I'm writing an app that copies some contents of the bundle into the applications
I'm writing a simple app that processes POST ed CSV files and am testing
I am writing an auto update client. It's a very simple app that: 1)

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.