Rails Setup

Rails Setup

  • Rails
  • Devise
  • GitHub

›Getting Started

General

  • Overview
  • Starting with rails?

Getting Started

  • Installation
  • Controller filters and helpers
  • Configuring Models
  • Strong Parameters
  • Configuring views
  • Configuring controllers
  • Configuring routes

Advanced Topics

  • I18n
  • Test helpers
  • OmniAuth
  • Configuring multiple models
  • ActiveJob integration
  • Password reset tokens and Rails logs
  • Other ORMs
  • Rails API mode

Guides

  • Guides list

Project

  • Extensions
  • Example Applications
  • Contributing
  • Bug reports
  • Additional information

Configuring views

We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.

Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:

$ rails generate devise:views

If you have more than one Devise model in your application (such as User and Admin), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set config.scoped_views = true inside the config/initializers/devise.rb file.

After doing so, you will be able to have views based on the role like users/sessions/new and admins/sessions/new. If no view is found within the scope, Devise will use the default view at devise/sessions/new. You can also use the generator to generate scoped views:

$ rails generate devise:views users

If you would like to generate only a few sets of views, like the ones for the registerable and confirmable module, you can pass a list of modules to the generator with the -v flag.

$ rails generate devise:views -v registrations confirmations
Last updated on 2019-7-7
← Strong ParametersConfiguring controllers →
Rails Setup 2019