Skip to content

How To: Manage users through a CRUD interface

Javix edited this page Mar 6, 2012 · 10 revisions

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 (map.devise_for :users and map.resources :users for Rails 2).

You must also set the :path_prefix to isolate the devise logic from your crud user controller:

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

In your UserController, 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 that to your update method:

if params[:user][:password].blank?
  params[:user].delete(:password)
  params[:user].delete(:password_confirmation)
end
Clone this wiki locally