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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:34:41+00:00 2026-05-30T04:34:41+00:00

I am getting this error while following the tutorial from railstutorial.org. Model class :

  • 0

I am getting this error while following the tutorial from railstutorial.org.

Model class : $APPLICATION_HOME/app/models/user.rb

# == Schema Information
#
# Table name: users
#
#  id         :integer         not null, primary key
#  name       :string(255)
#  email      :string(255)
#  created_at :datetime        not null
#  updated_at :datetime        not null
#

class User < ActiveRecord::Base

  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password

  #validations
  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, length: { minimum: 6 }

end

View page : $APPLICATION_HOME/app/views/show.html.erb file

<% provide :title, @user.name %>
<h1><%= @user.name %></h1>

RSpec file : $APPLICATION_HOME/app/spec/requests/user_pages_spec.rb

 require 'spec_helper'

    describe "UserPages" do

      subject { page }

      describe "signup page" do

        before { visit signup_path }

        it { should have_selector('h1', text: "Sign up") }
        it { should have_selector('title', text: full_title('Sign up')) }

      end

      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
    end

Here is factories.rb which I have put in $APPLICATION_HOME/spec/factories.rb

FactoryGirl.define do
  factory :user do
    name     "amit"
    email    "amit@gmail.com"
    password "foobar"
  end
end

A snapshot of Gemfile

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails'
end

Here is log I am getting while testing the spec.

Failures:

  1) UserPages profile page 
     Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined method `name' for nil:NilClass
     # ./app/views/users/show.html.erb:1:in `_app_views_users_show_html_erb__369651065_78543920'
     # ./spec/requests/user_pages_spec.rb:18:in `block (3 levels) in <top (required)>'

  2) UserPages profile page 
     Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined method `name' for nil:NilClass
     # ./app/views/users/show.html.erb:1:in `_app_views_users_show_html_erb__369651065_78543920'
     # ./spec/requests/user_pages_spec.rb:18:in `block (3 levels) in <top (required)>'

Finished in 0.68212 seconds
12 examples, 2 failures

The error comes at these two lines

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

Please help me to resolve these errors.

Thanks, Amit Patel

  • 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-30T04:34:42+00:00Added an answer on May 30, 2026 at 4:34 am

    It was typo in $APPLICATION_HOME/app/controllers/users_controller.rb

      def show
        @users = User.find(params[:id])
      end
    

    If you notice, the instance variable name is pluralized (@users) and I have used singular name (@user) in the erb template. That is why it is getting failed.

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

Sidebar

Related Questions

I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
I keep getting this error while trying to modify some tables. Here's my code:
All of a sudden I start getting this error while trying to open 2
in the aspx page i am getting this error while binding dropdown list Unable
I am using zendgdata library for google calendar. I am getting this error while
I'm Getting this error in my development log while uploadify is uploading the file
It has been quite a while since I am getting this error in the
While trying to host the CLR, I keep getting this: error C2440: 'function' :
Hi I'm getting the error while executing following code in MySQL : BEGIN DECLARE
I am getting this error while running a hadoop pipes program. The program compiles

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.