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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:12:46+00:00 2026-05-26T10:12:46+00:00

I am doing Michael Hartl’s Rails Tutorial screencast + online book on Chapter 10,

  • 0

I am doing Michael Hartl’s Rails Tutorial screencast + online book on Chapter 10, and I am stuck at the very last sub-chapter Destroying User.

Console output:

Failures:

      1) UsersController DELETE 'destroy' as an admin user should destroy the user

         Failure/Error: delete :destroy, :id => @user
         NameError:
           undefined local variable or method `users' for #<UsersController:0x00000104a2f698>
          ./app/controllers/users_controller.rb:47:in `destroy'
          ./spec/controllers/users_controller_spec.rb:321:in `block (5 levels) in <top (required)>'
          ./spec/controllers/users_controller_spec.rb:320:in `block (4 levels) in <top (required)>'

      2) UsersController DELETE 'destroy' as an admin user should redirect to the users page

         Failure/Error: delete :destroy, :id => @user
         NameError:
           undefined local variable or method `users' for #<UsersController:0x000001049bf370>
         ./app/controllers/users_controller.rb:47:in `destroy'
         ./spec/controllers/users_controller_spec.rb:326:in `block (4 levels) in <top (required)>'

users_controller.rb

class UsersController < ApplicationController
  before_filter :authenticate, :only => [:index, :edit, :update, :destroy]
  before_filter :correct_user, :only => [:edit, :update]
  before_filter :admin_user, :only => :destroy

  def index
  @users = User.paginate(:page => params[:page])
  @title = "All users"
  end

  def show
    @user = User.find(params[:id])
    @title = @user.name
  end

  def new
  @user = User.new
  @title = "Sign up"      
  end

  def create  
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      redirect_to @user, :flash => { :success => "Welcome to the Sample App!" }
    else
      @title = "Sign up"
      render 'new'
    end
  end

  def edit
    @title = "Edit user"
  end

  def update
    if @user.update_attributes(params[:user]) 
      redirect_to @user, :flash => { :success => "Profile updated." }
    else
    @title = "Edit user"
    render 'edit'
    end
  end

  def destroy
    User.find(params[:id]).destroy
    redirect_to users.path, :flash => { :success => "User destroyed." }
  end

  private

    def authenticate
      deny_access unless signed_in?
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_path) unless current_user?(@user)
    end

    def admin_user
      @user = User.find(params[:id])
      redirect_to(root_path) if !current_user.admin? || current_user?(@user)
    end
end

Users_controller_spec.rb:

    describe "DELETE 'destroy'" do

      before(:each) do
        @user = Factory(:user)
      end

      describe "as a non-signed-in user" do
        it "should deny access" do
          delete :destroy, :id => @user
          response.should redirect_to(signin_path)
        end
      end

      describe "as non-admin user" do
        it "should protect the action" do
          test_sign_in(@user)
          delete :destroy, :id => @user
          response.should redirect_to(root_path)
        end
      end

      describe "as an admin user" do

        before(:each) do
          @admin = Factory(:user, :email => "admin@example.com", :admin => true)
          test_sign_in(@admin)
        end

        it "should destroy the user" do
          lambda do
            delete :destroy, :id => @user
          end.should change(User, :count).by(-1)
        end

        it "should redirect to the users page" do
          delete :destroy, :id => @user
          flash[:success].should =~ /destroyed/i
          response.should redirect_to(users_path)
        end

        it "should not be able to destroy itself" do
          delete :destroy, :id => @admin
          lambda do
            delete :destroy, :id => @admin
          end.should_not change(User, :count)
        end
      end
  end   
end

I am a beginner but always in a habit of doing extensive researches (90% of the time I found answers by searching SO and Google) before posting any question here.

My last 2 unposted questions (found the answer before posting) I had was fixed by updating my Gemfiles (will_paginate and undefined _selector in rspec). Could this be it too?

Thanks for the concern and taking the time to read 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-05-26T10:12:47+00:00Added an answer on May 26, 2026 at 10:12 am

    Found the typo (duh!) that fixes the issue above:

    def destroy
        User.find(params[:id]).destroy
        redirect_to users_path, :flash => { :success => "User destroyed." }
      end
    

    instead of “users_path” i did “users.path”

    Noticed it when trying to delete from browser.

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

Sidebar

Related Questions

Im doing Michael Hartl's excellent tutorial series on ruby on rails here: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book and
Currently doing the Ruby On Rails Tutorial by Michael Hartl, and am starting on
In Michael Hartl's Ruby on Rails Tutorial, ch 7.2.3 , rspec is returns the
I'm running through Michael Hartl's Rails Tutorial . I'm trying to verify the title
In Michael Hartl's tutorial he has a module SessionsHelper , which has a method
I recently set up a new account with github. I'm following a Rails tutorial
I have been doing Michael Foord's IronPython&Winforms tutorials in the interactive console. Is it
Doing odd/even styling with jQuery is pretty easy: $(function() { $(.oddeven tbody tr:odd).addClass(odd); $(.oddeven
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following

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.