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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:26:30+00:00 2026-05-27T11:26:30+00:00

in a Rubyonrails application i want only logged in users to enterinto the inner

  • 0

in a Rubyonrails application i want only logged in users to enterinto the inner pages?
how can i redirect the direct entered urls to index page?

in php if(!isset($_SESSION[id]) { header(“location:index.php”) }, how this can be implemented in ruby on rails

  • 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-27T11:26:31+00:00Added an answer on May 27, 2026 at 11:26 am

    here goes

    In application_controller.rb:

    Putting this code in application_controller will make it available to all your controllers.

    class ApplicationController < ActionController::Base
      protect_from_forgery
    
      protected
    
    def confirm_logged_in
        unless session[:id]
            flash[:notice] = "Please log in"
            redirect_to :root
            return false
        else
            return true
        end
    end
    
    end
    

    Then you can make use of this method in any of the controllers that require it, for eg

    If you need to confirm that users are logged in for the show action, then

    class UsersController < ApplicationController
    before_filter :confirm_logged_in, :only => [:show]
    
    def show
        #all your code
    end
    
    end
    

    should work, as this will confirm that users accessing this show url have logged in.

    For more info checkout this link to rails guides on filters. There could be more efficient ways of achieving this as well.

    However, i would suggest using a gem like Cancan (Github) as i have used this in many apps and works well. The code presented above is basic and there are many better and advanced ways to handle this but it should do the job.Hope it helps.

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

Sidebar

Related Questions

SA I have a application written in RubyonRails and I want to make him
I've done scaffolding using the method described here http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator However, I want to know
It seems http://api.rubyonrails.org/ is not for rails 3. Where can I get the api
In rails, on can show the active routes with rake ( http://guides.rubyonrails.org/routing.html ): $
In my application a user can create an appointment. class User has_many :appointments end
I have been happily developing my application locally and using sqlite3 as database only
I'm running a RubyOnRails application with the following setup: apache 2.2.9 passenger 2.2.8 rails
Cookies maximum size in rails application,as per rails guide it is 4 KB. http://guides.rubyonrails.org/security.html#session-storage
I'm using the http://guides.rubyonrails.org/getting_started.html as an example to help me create my own application.
I want to use the Date::ABBR_MONTHS constant in my rails application. I see the

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.