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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:42:49+00:00 2026-06-11T22:42:49+00:00

So I am working through the Ruby on Rails 3 Tutorial. I am currently

  • 0

So I am working through the Ruby on Rails 3 Tutorial. I am currently on section 7.1.3 Testing the User show page using factories.

The code is working and pulls the proper gravatar image however I keep getting an error when running my tests.

Here is the error:

Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined method `downcase' for nil:NilClass

Here is the code from the show.html.erb file:

<% provide(:title, @user.name) %>
<h1>
  <%= gravatar_for @user %>
  <%= @user.name %> 
</h1>
<%= @user.name %>, <%= @user.email %>

Here is the code from the users_helper.rb file:

module UsersHelper
  # Returns the Gravatar (http://gravatar.com/) for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end
end

Here is the code from factories.rb file:

FactoryGirl.define do
  factory :user do
    name "Curtis Test"
    email "test@gmail.com"
    password "foobar"
    password_confirmation "foobar"
  end
end

Here is the code from the test file user_pages_spec.rb

require 'spec_helper'

describe "User Pages" do
  subject { page }

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }

    before { visit user_path(user) }
    it { should have_selector('h1', text: user.name) }
    it { should have_selector('title', text: user.name) }
  end

  describe "signup page" do
    before { visit signup_path }
    it { should have_selector('title', text: full_title('Sign Up')) }
  end
end
  • 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-11T22:42:50+00:00Added an answer on June 11, 2026 at 10:42 pm

    I discovered my problem. It had nothing to do with FactoryGirl. The problem was in my user model (user.rb), the line that was causing the issue was

      before_save { |user| user.email = user.email.downcase! }
    

    The bang after the downcase was causing the email address to be saved as nil since the return of the downcase! is nil. Once I removed that and made the line look like the following it worked just fine.

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

    The way I found it was to load the rails console in test environment and tried to create a new user. I noticed that everything was fine but the email was null.

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

Sidebar

Related Questions

Hi i'm working through the Hartl's Ruby on Rails Tutorial and i'm stuck with
I am currently working through Michael Hartl's Rails Tutorial while experimenting with some other
I am working back through the Ruby on Rails 3 Tutorial and trying to
I am working through the Ruby on Rails Tutorial by Michael Hartl and I
I am just trying to walk through this tutorial http://jimneath.org/2011/03/24/using-redis-with-ruby-on-rails.html#redis_and_rails And when I put
I'm working through the Ruby on Rails Tutorial at http://railstutorial.org/ , chapter 4, listing
I'm working through the Ruby on Rails tutorial and just made a Comment model
I am working through the Ruby on Rails 3 tutorial book and typed the
I'm working through the Ruby on Rails 3 Tutorial: Learn Rails by Example by
I am working through Michael Hartl's Ruby on Rails Tutorial Chapter 5 exercises 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.