Devise: Customize controller and views

Sonntag, 10. April 2011, 12:38 Uhr | roberto@vasquez-angel.de |

Devise uses built-in controllers and views by default. If you want to customize them, you have to add them to your rails application.

Assume you have a customer login.

Customizing the controller

Create a new controller at Rails.root/app/controllers/customers/sessions_controller.rb:

class Customers::SessionsController < Devise::SessionsController
end

Customize your Rails.root/config.routes.rb to use the controller:

devise_for :customers, :controllers => { :sessions => "customers/sessions" }

Customizing the views

First you’ll have to add support for scoped views. Uncomment following lines in your Rails.root/config/initializers/devise.rb:

Devise.setup do |config|
  config.scoped_views = true
end

Then generate the views:

rails generate devise:views customers