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

  • Home
  • SEARCH
  • 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 7846213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:30:12+00:00 2026-06-02T17:30:12+00:00

I’m trying to incorporate Devise and Cancan into a web app. I want users

  • 0

I’m trying to incorporate Devise and Cancan into a web app. I want users with :role => “admin” to be able to delete users, and Devise’s destroy action only allows users to delete themselves, so I’ve created a custom action for this purpose. (To override the plugin’s controller file, I’ve copied the registrations controller over to app/controllers/registrations_controller.rb.)

Here is my custom action in my registrations_controller.rb:

def destroy_user_account
    @user = User.find_by_id(params[:user])        
    @user.destroy
    redirect_to profiles_path, :flash => { :success => "User deleted!" }
    authorize! :destroy, User, :message => "You don't have authorisation to delete this user."          
end

Here is how I’m trying to use it, in a link on the page where you view a user’s profile. (I have things set up so that each user has_one profile; profiles are what you see at the front end. A profile is automatically created in the profiles table on user registration.)

    <% if can? :update, @profile %>
        | <%= link_to 'Edit Profile', edit_profile_path(@profile) %>
        | <%= link_to 'Edit Settings', edit_settings_path %>
    <% end %>               
    <% if can? :destroy, @profile.user %>
        | <%= link_to "Delete User", destroy_user_account(@profile.user), 
                        :class => "delete", 
                        :confirm => "Are you sure?",
                        :title => "Delete #{@profile.user.name}"
    %>
    <% end %>   

My tests are showing 2 failures that I can’t resolve:

1) ProfilesController GET show when signed in as an admin should
have a link to edit the profile
Failure/Error: get :show, :id => @profile
ActionView::Template::Error:
undefined method destroy_user_account' for #<#<Class:0x105b474a8>:0x1057f32e8>
# ./app/views/profiles/show.html.erb:41:in
_app_views_profiles_show_html_erb___917863454_2195331000_0′
# ./spec/controllers/profiles_controller_spec.rb:143

2) ProfilesController GET show when signed in as an admin should
have a link to delete the user’s account (using the
destroy_user_account action in the registrations controller)
Failure/Error: get :show, :id => @profile
ActionView::Template::Error:
undefined method destroy_user_account' for #<#<Class:0x105b474a8>:0x105806d20>
# ./app/views/profiles/show.html.erb:41:in
_app_views_profiles_show_html_erb___917863454_2195331000_0′
# ./spec/controllers/profiles_controller_spec.rb:148

Also, when I try it out in my browser, clicking on the “Delete user” link gets me the following error:

Routing Error

No route matches “/destroy-user-account/2”

Here are the routes that should cover this:

devise_for :users, #:path => ”,
:skip => [ :confirmations, :passwords, :registrations ],
:controllers => { :registrations => “registrations” } do

# Routes for ACCOUNT REGISTRATIONS
get     "join",                           :to => "registrations#new",    :as => :new_user_registration
post    "join",                           :to => "registrations#create", :as => :user_registration
get     "settings/account",               :to => "registrations#show",   :as => :settings
get     "settings/account/edit",          :to => "registrations#edit",   :as => :edit_settings
put     "settings/account",               :to => "registrations#update", :as => :update_settings
delete  "close-my-account/:id",           :to => "registrations#destroy", :as => :close_my_account
delete  "destroy-user-account/:id",      :to => "registrations#destroy_user_account", :as => :destroy_user_account

Can anyone help with what I’m doing wrong?

  • 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-02T17:30:15+00:00Added an answer on June 2, 2026 at 5:30 pm

    In the browser it isn’t matching the route because you’re sending a GET request but the route only matches a DELETE request. The test fails because the route gives the name destroy_user_account_path instead of destroy_user_account.

    Try:

    <%= link_to "Delete User", destroy_user_account_path(@profile.user), 
                            :class => "delete", 
                            :confirm => "Are you sure?",
                            :title => "Delete #{@profile.user.name}"
                            :method => :delete
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

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.