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

The Archive Base Latest Questions

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

I have been following the Railscast #270 found Rails Cast #270 about implementing Authentication

  • 0

I have been following the Railscast #270 found Rails Cast #270 about implementing Authentication in Rails 3.1. What I would like to do is have the ability in my templates to have different links displayed if a user is logged in. It should look something like this.

If user logged in
  Display link to Profile
  Display logout
If user logged out
 Display link to register
 Display link to login

I think I can figure out the link to various places from theRailsTutorial, but I’m stuck on how to tell if a user is signed in or not.

Using the rails tutorial I found this snippet

 <% if signed_in? %>
     <li><%= link_to "Profile", current_user %> sfsdfsdf</li>
 <% end %>

Which doesn’t work when I put the following in my sessions helper:

    def signed_in?
      !@current_user.nil?  
end

How would you make this work?

  • 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-26T10:45:30+00:00Added an answer on May 26, 2026 at 10:45 am

    Use current_user.

    so just

     <% if current_user %>
         <li><%= link_to "Profile", current_user %> sfsdfsdf</li>
     <% end %>
    

    btw in HAML that would be just

     -if current_user
       %li= 
         link_to "Profile", current_user, sfsdfsdf
    

    (the ends get implied – both for the HTML <li> tag (i.e. the </li>) AND for the ruby if statement!)
    For anyone not using HAML this should wet your appetite 🙂

    current_user itself uses @current_user and it gets set up in your application controller as in:

      helper_method :current_user
    
      private
    
      def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been following this course in youtube and it was talking about how
I am using Rails 3.1 and have been using this railscast tutorial to implement
I have been following the railscasts 'Nested Model Form Parts 1 & 2' about
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
I have been following http://learn.iis.net/page.aspx/806/seo-rule-templates/ , which is a nearly perfect guide to creating
I've been following RailsCast 197 to try this nested models/forms and have cracked my
I have been following this tutorial in order to get username authentication with transport
I have been following a good tutorial about creating a Button skin that allows
I have been following the answer of this question: How to update existing object
I have been following the usage of JavaScript for the past few years, and

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.