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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:24:22+00:00 2026-05-31T09:24:22+00:00

Following Hartl’s railtutorial. When I try to log in, it takes me to the

  • 0

Following Hartl’s railtutorial. When I try to log in, it takes me to the correct page, but “Successful login!” does not flash on the interface. Also, when I try to sign out, I get a Routing Error: No route matches [GET] "/sessions/1".

Any help would be appreciated!

Here is my sessions_controller.rb:

class SessionsController < ApplicationController

def new
  @title = "Log in"
end

def create
  user = User.authenticate(params[:session][:email], 
                           params[:session [:password])     
  if user.nil?
    flash.now[:error] = "Invalid email/password combination."
    @title = "Sign in"
    render 'new'
  else
    flash[:success] = "Successful login!"
    sign_in user
    redirect_back_or user
  end
end

def destroy
  sign_out
  redirect_to root_path
end

end

Here is my routes.rb:

SampleApp::Application.routes.draw do

  #resources :users    this is the line I removed to get my code to work
  resource :user #this is the lined I added to get my code to work

  resources :sessions, :only => [:new, :create, :destroy]   


  match '/sessions', :to => 'users#show'
  match '/signup', :to => 'users#new'
  match '/login', :to => 'sessions#new'
  match '/logout', :to => 'sessions#destroy'

  root :to => 'pages#home'

Changing resources :users to resource :user seems to allow me to “sign in” and “sign out” except that the flash success still does not appear on the user interface. This leads me to believe that there is an error in my create method.

Here is my sessions_helper.rb:

module SessionsHelper

def sign_in(user)
  cookies.permanent.signed[:remember_token] = [user.id, user.salt]
  self.current_user = user
end


def signed_in?
  !current_user.nil?
end

def current_user=(user)
  @current_user = user
end

def current_user
  @current_user ||= user_from_remember_token
end

def current_user?(user)
  user == current_user
end

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

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

private

def user_from_remember_token
  User.authenticate_with_salt(*remember_token)
end

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

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

def clear_return_to
  session[:return_to] = nil
end
end

Edited: Solution posted in code.

  • 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-31T09:24:24+00:00Added an answer on May 31, 2026 at 9:24 am

    i think you should user just flash[:success] and flash[:error] and not the flash.now

    and what link are you using for loging out?

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

Sidebar

Related Questions

Following Hartl's RailTutorial for Rails(3.2). I keep getting this error message or oddly a
I am completely new to ror and am following Michael Hartl's tutorial but I
Following Michael Hartl's Rails 2.3 tutorial. Excellent, so far, but I am stuck on
I was following Michael Hartl's tutorial to build a sign up form with login.
I'm following the demo_app in Michael Hartl's book Ruby on Rails 3 Tutorail .
I'm following the Rails Tutorial by Michael Hartl and I'm getting an unexpected error/failed
I am running Rails 3.0.1 and Rspec 2.0.1. I am following M. Hartl's Ruby
Following Hartl's railstutorial and I changed my error-messages partial to work with other objects
Following Hartl's Railstutorial on Chapter 10 where we protect user edit pages so that
I am following Michael Hartl's RoR tutorial, and it is covering the basics of

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.