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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:48:45+00:00 2026-05-26T03:48:45+00:00

I was following Michael Hartl’s tutorial to build a sign up form with login.

  • 0

I was following Michael Hartl’s tutorial to build a sign up form with login. I thought I would try and add a remember me check box to the login form and make it’s value default at 0 and then 1 when checked.

I added an if statement in my sessionshelper:

module SessionsHelper

  def login(user)
    if params[:remember_me]
    cookies.permanent.signed[:remember_token] = [user.id, user.password_salt]
    current_user = user
   else
    cookies[:remember_token] = [user.id, user.password_salt]
    current_user = user
   end
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    @current_user ||= user_from_remember_token
  end

  def logged_in?
    !current_user.nil?
  end

  def logout
    cookies.delete(:remember_token)
    current_user = nil
  end

  private

  def user_from_remember_token
    User.authenticate_with_salt(*remember_token)
  end

  def remember_token
    cookies.signed[:remember_token] || [nil, nil]
  end

end

….but for some reason when ever I log in with boxed checked or not checked the cookie expiry time and date is never set. It always says “At end of session” when I check cookie info in firefox. Am I missing something?

my controller:

class SessionsController < ApplicationController

  def new

  end


  def create
    user = User.authenticate(params[:session][:email], params[:session][:password])
    if user.nil?
      flash.now[:error] = "Invalid email password combination"
      render 'new'
    else
      login user
      redirect_to user
    end
  end

  def destroy
    logout
    redirect_to root_path
  end
end

view:

<%= form_for(:session, :url => sessions_path) do |f| %>
  <%= f.text_field :email, :placeholder => "Email" %>      
  <%= f.password_field :password, :placeholder => "Password" %>     
  Remember me? <%= f.check_box :remember_me, :value => 1 %>
  <%= f.submit "Log in", :id => "login_submit" %>
  <% end %>

Help is appreciated.

  • 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-26T03:48:45+00:00Added an answer on May 26, 2026 at 3:48 am

    The following solved my issue

     def login(user)
        if params[:session][:remember_me] == "1"
        cookies.permanent.signed[:remember_token] = [user.id, user.password_salt]
        current_user = user
       elsif params[:session][:remember_me] == "0"
        cookies.signed[:remember_token] = [user.id, user.password_salt]
        current_user = user
       end
      end
    

    view:

        <%= form_for(:session, :url => sessions_path) do |f| %>
          <%= f.text_field :email, :placeholder => "Email" %>      
          <%= f.password_field :password, :placeholder => "Password" %>     
          Remember me? <%= f.check_box :remember_me %>
          <%= f.submit "Log in", :id => "login_submit" %>
          <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the Rails Tutorial by Michael Hartl and I'm getting an unexpected error/failed
I am following Michael Hartl's RoR tutorial, and it is covering the basics of
New to Ruby on Rails and having a problem when following Michael Hartl's tutorial.I'm
I'm following Chapter 5 of the Michael Hartl tutorial. When I run the following
I'm new to Programming and was following the Rails Tutorial by Michael Hartl when
I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
I am new to RoR3 am following along with the RoR3 Michael Hartl Tutorial.
I am completely new to ror and am following Michael Hartl's tutorial but I
(ruby 1.9.2, rails 3.1) Following Michael Hartl's tutorial. Spent more than a day trying
I'm following Ruby on Rails Tutorial: Learn Rails by Example, by Michael Hartl. http://ruby.railstutorial.org/chapters/a-demo-app#sec:a_micropost_microtour

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.