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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:29:43+00:00 2026-05-26T06:29:43+00:00

I am a newbie in Rails. I try to build a simple authenticate system,

  • 0

I am a newbie in Rails. I try to build a simple authenticate system, to application_controller I put following lines:

  def check_session
    if session[:user]
      if session[:expiry_time] < 10.minutes.ago
        reset_session
      flash[:warning] = 'You was logout.' 
        redirect_to root_url
      else
        session[:expiry_time] = Time.now
      end
    else
      #... authenticate
      session[:expiry_time] = Time.now
      flash[:warning] = 'You was logout.' 
      redirect_to root_url
    end
  end  

My problem is in one action – in this action I check, if the user is log in or not. And if the user is log in, so I will render one template, and if not, so I will render the second one. It looks like:

<% unless session[:user].nil? %>
  <%= render :template => 'template_for_login_user' %>
<% else %>
  <%= render :template => 'template_for_not_login_user' %>
<% end %>

And here is the problem – this doesn’t works me. At least… well – if I am not log in, so will be render the template template_for_not_login_user and if I am, so template_for_login_user. This is right.

But if I am log in and I am on the template_for_login_user, but I am 15min idle => the session will be expired => I should be redirect to login form. But here is the problem – I am 15 minutes idle and I refresh this page, so I am still on the action template_for_login_user – and this is the problem…

I would like to ask you – can you help me please, where could be a problem? What I’m doing wrong?

  • 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-26T06:29:44+00:00Added an answer on May 26, 2026 at 6:29 am

    In your ApplicationController, did you add a line like this :

    before_filter :check_session
    

    if some controller action don’t need the user to be authenticated, you can add this:

    skip_before_filter :check_session, :only=> [:index, :search, etc..]
    

    in this example, this would skip your before_filter :check_session on action : index and search. This way you have a global behavior that always check the session for a user logged on. But you can skip this in particular controller where some actions don’t need the user to be authenticated

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

Sidebar

Related Questions

Rails newbie here struggling with a small project. I am creating a simple ship
I'm a newbie Rails developer who is getting the following error when trying to
Hi (huge Rails newbie here), I have the following models: class Shop < ActiveRecord::Base
Rails newbie here. Can anyone please explain the difference to me between the following
i am newbie in rails and try to perform left join in mysql. there
Rails newbie here, trying to get a new controller working. When I try to
I'm Rails newbie. How to make a form which allows user to choose a
I am a rails newbie, have a simple question: I have two tables, valor,
As a Rails newbie, I am running into an issue in which I can
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a

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.