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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:26:52+00:00 2026-06-12T06:26:52+00:00

after finishing Michael Hart’s tutorial on rails, I’m giving making a simple app of

  • 0

after finishing Michael Hart’s tutorial on rails, I’m giving making a simple app of my own a try.

I managed to create the users resource, and am now trying to create a sessions resource, to track when someone is logged in. I’m getting some really wacky results.

1) I was trying to display different menu options for when someone is logged in, and for when someone is logged out. It works, except it behaves the opposite to the way I expected it ! i.e when I write

        <ul class="nav pull-right">
          <% if signed_in? %>
               #menu for registered users
          <% else %>
               #menu for unregistered users             
          <% end %>
        </ul>

When I’m logged in, the #menu for unregistered users shows up, and when I’m logged out, the #menu for registered users shows up.

2) I’m also trying to create a link to the user’s admin page, which is the basically the user’s id page.

I put this as the following as the link code

<%= link_to "Admin", user_path(current_user) %>

And got the error

No route matches {:action=>”show”, :controller=>”users”, :id=>nil}

This makes me think that the current_user I defined in the sessions helper is not being saved, but than I think, but I’m not sure why.

Here’s the code I have for the
User Model

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password

  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token

  validates :name, presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence:   true,
                    format:     { with: VALID_EMAIL_REGEX },
                    uniqueness: { case_sensitive: false }
  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true

  private

        def create_remember_token
          self.remember_token = SecureRandom.urlsafe_base64
        end

end

Sessions Controller

class SessionsController < ApplicationController

def new
end

def create
    user = User.find_by_email(params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
        sign_in user
        redirect_to user
    else
        flash.now[:error] = 'Invalid Email/Password Combination' #Not quite right; 
        render 'new'
    end
end

end

SessionsHelper

module SessionsHelper
  def sign_in(user)
    cookies.permanent[:remember_token] = user.remember_token
    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.find_by_remember_token(cookies[:remember_token])
  end
end

ApplicationController

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
end

Thoughts?

  • 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-12T06:26:53+00:00Added an answer on June 12, 2026 at 6:26 am

    Thanks for the help guys! It seemed like I had two errors — 1) I didn’t sign in users when they registered in the users controller and 2) I didn’t restart the server, and do a db:reset. After trying that, the other problems, having to do with the signout not working, fixed.

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

Sidebar

Related Questions

After finishing Michael Hartl's tutorial on Rails, my first pet project is building a
After following the RoR getting started tutorial, I added another model as: $ rails
When I was first started teaching myself programming, after finishing a tutorial I would
I've followed this tutorial to upgrade to mysql 5.5. After finishing all the steps
After finishing coding for my app, I started to get into the optimization part.
I'm following the Jobeet Tutorial Day 7 for Symfony. After finishing The Category Link
I have developed a simple Cake application and after finishing coding of it, I
I have try to add MySQL database to solr index. After finishing dataimport process,
how can i activate the readonly back after finishing the edit of the input
I want to display a success msg after finishing an Ajax call. I tried

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.