简体   繁体   中英

Remove users from database (Ruby on Rails, Devise)

I'm trying to create a button to remove users from the database.

In the routes I have:

  devise_for :users, :controllers => { registrations: 'registrations' }
  match 'users/:id' => 'registrations#destroy', :via => :delete, :as => :admin_destroy_user

registration_controller :

def destroy
    @user = User.find(params[:id])
    if @user.destroy
      redirect_to root_path
    end
end

_backoffice.html.erb file:

<%= button_to 'Delete', admin_destroy_user_path(user.id), :class => 'btn btn-danger btn-sm', :method => :delete, data: {:confirm => 'Tem a certeza que quer apagar este utilizador?'} %>

And this is the error I'm getting:

NoMethodError in RegistrationsController#destroy

undefined method `name' for nil:NilClass

  def resource_name
    devise_mapping.name
  end
  alias :scope_name :resource_name

Thanks for any help.

The error indicates that there is no method named destroy in the RegistrationsController . But in your post, you reference this controller as: registration_controller (ie with no "s")

Perhaps you have defined your RegistrationController as singular, not plural?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM