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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:59:49+00:00 2026-05-13T16:59:49+00:00

I followed the official Authlogic tutorial but something came up. I successfully created a

  • 0

I followed the official Authlogic tutorial but something came up.

I successfully created a user, but when I try to show his profile page, I get the following error:

undefined method `email' for #<UserSession: {:unauthorized_record=>"<protected>"}>

Here’s the relevant code:

# user.rb
class User < ActiveRecord::Base  
  acts_as_authentic do |c|
    c.crypto_provider = Authlogic::CryptoProviders::BCrypt
    c.require_password_confirmation(false)
  end  
  attr_accessible :username, :email, :password  
end

# users_controller.rb    
def show
  @user = @current_user
end

# application_controller.rb
private
  def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
  end

  def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session and current_user_session.user
  end

I think that’s the entire chain. And here’s the view:

# views/users/show.html.erb
<%=h @user.username%>
email: <%=h @user.email %>
<%= link_to "Edit", edit_account_path %>

When I remove the “email” line, I get a page with only the “Edit” link. The username does not appear. However, when I add <%= debug @user %> to see what’s going on, it correctly prints the values for email and username as stored in the database. I have no idea why it does not print @user.username, and why it throws an error when I try to print @user.email.

It should be noted that the show.html.erb layout of the tutorial uses @user.login, and it works. I just changed “login” to “username”.

Furthermore, when I click “Edit”, I get the same original error:

undefined method `email' for #<UserSession: {:unauthorized_record=>"<protected>"}>

Here’s the edit layout and the form partial used:

# views/users/edit.html.erb
<h1>Edit My Account</h1>

<% form_for @user, :url => account_path do |f| %>
  <%= f.error_messages %>
  <%= render :partial => "form", :object => f %>
  <%= f.submit "Update" %>
<% end %>
<br />
<%= link_to "My Profile", account_path %>

#views/users/_form.erb
<%= form.label :username %><br />
<%= form.text_field :username %><br />
<br />
<%= form.label :email %><br />
<%= form.text_field :email %><br />
<br />
<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
<%= form.password_field :password %><br />
<br />

Again, all taken verbatim from the tutorial, that just works.

I’m running Rails 2.3.2 and the latest Authlogic (just installed today, whatever version that is), and as far as my tired and frustrated brain can tell, I do have all required fields in the database, and they are spelled correctly.

What’s going on?

  • 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-13T16:59:50+00:00Added an answer on May 13, 2026 at 4:59 pm

    Well, this is embarrassing…

    It turns out the problem was my predilection for natural language. Here’s the current_user method as laid out in the tutorial:

    def current_user
      return @current_user if defined?(@current_user)
      @current_user = current_user_session && current_user_session.user
    end
    

    However, when applying it to my case, I swapped && for and, and as a result current_user_session.user was not being taken into account. Which is why it kept saying UserSession this and that. I thought that was weird, but couldn’t see where it was coming from. Now I do.

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

Sidebar

Related Questions

I followed this tutorial (official documentation for symfony 1.4). The project is created but
I've followed this otherwise excellent tutorial on getting Xen working with Ubuntu but am
I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
I followed Apple's instructions on how to create an Ad Hoc Distrubution bundle but
Program followed by output. Someone please explain to me why 10,000,000 milliseconds from Jan
I followed the commonly-linked tip for reducing an application to the system tray :
Ok I followed the steps for setting up ruby and rails on my Vista
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
I have followed the blog post written by Steve Sanderson at blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc . It

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.