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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:17:40+00:00 2026-06-18T15:17:40+00:00

The idea is to make it so admin users can’t destroy themselves. I have

  • 0

The idea is to make it so admin users can’t destroy themselves.
I have written the following test:

describe "as admin user" do
  let(:admin) { FactoryGirl.create(:admin) }
  before { valid_signin admin }

  describe "should not be able to delete himself by submitting a DELETE request to the Users#destroy action" do
    specify do
      expect { delete user_path(admin) }.not_to change(User, :count).by(-1)
    end
  end
end

and modified the destroy action thus:

def destroy
  @user = User.find(params[:id])
  unless current_user?(@user)
    User.find(params[:id]).destroy
    flash[:success] = "User destroyed."
    redirect_to users_url
  end
end

(You can only access the destroy action if you’re an admin user).

The test should now pass but it does not. I get the following error message:

Failure/Error: expect { delete user_path(admin) }.not_to change(User, :count).by(-1)
     ActionView::MissingTemplate:
       Missing template users/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.

I do not understand the missing template error message, and I do not see why the test does not pass.

  • 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-18T15:17:41+00:00Added an answer on June 18, 2026 at 3:17 pm

    Try changing your destroy action to something like this and see if your test passes:

    def destroy
      user = User.find(params[:id])
      unless current_user?(user)
        user.destroy
        flash[:success] = "User destroyed."
      else
        flash[:error] = "You can't destroy yourself."
      end
      redirect_to users_url
    end
    

    I think the issue is that you’re only redirecting to the users_url if you successfully destroy a user. If you don’t (ie the admin is attempting to destroy itself), then there is no redirect, and Rails will begin looking for a view called destroy.html.erb, not find one anywhere, and raise an exception. This is also why the user variable in the method changes from @user to user: a local variable will do instead of an instance variable as it doesn’t need to be used in a view.

    If this isn’t the issue, please edit your question to include a link to the Github repo with your current code.

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

Sidebar

Related Questions

Idea: I want to make smth like real time electronic blackboard. Many users have
I have a idea to make table like this 1. something1 2. something2 3.
We have an application where users can be created by an administrator and assigned
I need to make a following project: User goes to Index page Loggs in
I had made a site for client in which users can make request for
Let's say we have a User Model that has many Posts. The Posts Model
I have four different types of users login in to my website like admin
I have a one to many relationship between Admins and Users. Admin has_many :users
I have a DB table that uses the following schema: CREATE TABLE users (id
Is it a good or bad idea to make setters in java return this?

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.