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

  • Home
  • SEARCH
  • 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 7796851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:29:52+00:00 2026-06-01T23:29:52+00:00

I am using devise and cancan with rails 3.2.1 and I’m having an unusual

  • 0

I am using devise and cancan with rails 3.2.1 and I’m having an unusual problem that I know can be refactored and simplified, but after much searching, I’m stuck.

I have first_name and last_name fields in the user model and have successfully displayed the full name of the user in the users/show.html.erb view using this code:

<%= @user.first_name + " " + @user.last_name %>

And I was successfully displaying a link to the user’s show page in the header using:

<% if user_signed_in? %>
  <li><%= link_to @user.first_name + " " + @user.last_name, current_user %></li>
<% end %>

But, and I can’t figure this one out, after working on another part of the app, the header started giving me an undefined method error message…

In any case, I know there is a much better way to define and work with user names and I have tried some things out, such as adding a name method to the user model, but as you can clearly tell from this post, I am a beginner and have not been able to make that work.

Please let me know if you have any ideas on how to best work with users names in an application like this.

  • 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-01T23:29:54+00:00Added an answer on June 1, 2026 at 11:29 pm

    Where are you defining @user? I’m willing to bet that it’s in your UsersController show action, which means it’s defined for your header in that action only.

    Try replacing your header code with this:

    <% if user_signed_in? %>
      <li><%= link_to current_user.first_name + " " + current_user.last_name, current_user %></li>
    <% end %>
    

    The trick is that Devise makes current_user always available when the user is signed in. You don’t have to worry about setting a @user instance variable.

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

Sidebar

Related Questions

I am using devise and create login with Facebook using omniauth, but having problem
I have a rails app that is using Devise perfectly in development. I have
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I'm using devise and cancan in a Rails 3.2 project. I have an event
I'm using Devise and CanCan to create a backbone.js front-end and Rails 3.0.7 for
I'm using Cancan, Devise, Rails 3 for my ordering application. Each user has many
Can anyone point me towards documentation on this? I'm using Devise + CanCan in
I am using cancan, devise, and omniauth in a rails app. I'm quite happy
I'm developing a Rails 3 app using Devise and CanCan. The app allows anonymous
I have been using devise for authentication and cancan for authorization in my application.

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.