Skip to content

How To: Manage users through a CRUD interface

slothbear edited this page Sep 3, 2012 · 12 revisions
Clone this wiki locally

Devise is great because of its flexibility. Performing basic CRUD actions on the User model is actually no different than creating CRUD actions for anything else in Rails.

There are a couple things to remember though:

Make sure to put your resources :users below the devise_for :users route.

Since the registration routes and user managing routes can conflict, you need to change one of them. You can either put devise under a specific prefix:

devise_for :users, :path_prefix => 'my'
resources :users

Or your users

devise_for :users
scope "/admin" do
  resources :users
end

In your `UsersController`, you will also need to remove the password key of the params hash if it’s blank. If not, Devise will fail to validate. Add something like this to your update method:

if params[:user][:password].blank?
  params[:user].delete(:password)
  params[:user].delete(:password_confirmation)
end
Something went wrong with that request. Please try again.