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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:44:49+00:00 2026-05-23T07:44:49+00:00

I get the following error when running rspec spec/controllers/users_controller_spec.rb in section 7.3.1 of Michael

  • 0

I get the following error when running rspec spec/controllers/users_controller_spec.rb in section 7.3.1 of Michael Hartl’s Rails Tutorial:

  Failure/Error: get :show, :id => @user
  ActionController::RoutingError:
  No route matches {:id=>#<User id: 1, #rest is data from the factories.rb file....

Here’s my code for the users_controller_spec.rb file:

require 'spec_helper'
require 'factories'

describe UsersController do
render_views

describe "GET 'show'" do
before(:each) do
  @user = Factory(:user)
end

it "should be successful" do
  get :show, :id => @user
  response.should be_success
end

it "should find the right user" do
  get :show, :id => @user
  assigns(:user).should == @user
end
end

describe "GET 'new'" do
it "should be successful" do
  get 'new'
  response.should be_success
end

it "should have the right title" do
    get 'new'
    response.should have_selector("title", :content => "Sign up")
end
end
end

Here is my factories.rb code:

Factory.define :user do |user|
user.name                   "Michael Hartl"
user.email                 "mhartl@example.com"
user.password              "foobar"
user.password_confirmation  "foobar"
end

I inserted these lines in Spec_Helper in regards to ‘factory_girl’:

require 'factory_girl'
Factory.find_definitions

Any idea what’s causing the routing error?

Here is my routes.rb code:

SampleApp::Application.routes.draw do
get "users/new"

match '/signup', :to => 'users#new'

match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'

root :to => 'pages#home'

The author’s note regarding using – get :show, :id => @user instead of using – get :show, :id => @user.id:

” Second, note that the value of the hash key :id, instead of being the user’s id attribute @user.id, is the user object itself:
get :show, :id => @user

We could use the code:
get :show, :id => @user.id
to accomplish the same thing, but in this context Rails automatically converts the user object to the corresponding id. It does this by calling the to_param method on the @user variable.

  • 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-23T07:44:50+00:00Added an answer on May 23, 2026 at 7:44 am

    You are missing a route to the show action for users. You can add something like this to the routes.rb file.

    match "/users/:id" => "users#show"
    

    If you want the normal CRUD actions, you can get rid of your users/new route and instead of the match line above, just declare them all with a single line:

    resources :users
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running rspec I get the following error: no such file to load --
I am running Rails 3.0.1 and Rspec 2.0.1. I am following M. Hartl's Ruby
I'm running through Michael Hartl's Rails Tutorial . I'm trying to verify the title
I get the following error when running my Visual Studio 2008 ASP.NET project (start
We get the following error when running at test: ContextSwitchDeadlock was detected Message: The
I get the following error when running FXCop: CA1800 : Microsoft.Performance : 'obj', a
I get the following error pretty regularly when compiling in Visual Studio and running
When running a Python program that reads from stdin, I get the following error:
Why do I get following error when trying to start a ruby on rails
I am using GWT2.0.1,when I am running web application then I get following error

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.