Customizing Devise views in Rails

Ruby on-RailsDeviseViews

Ruby on-Rails Problem Overview


I'm using devise for user auth, but I have nice mockups for the signup, login, etc. pages. I've already done the rails generate devise:views User command and have all of the views in the views folder, however, when I replaced the registration/new.html.erb with my own new.html.erb, nothing changes nor looks different. It's as if I had done anything.

Anyone know what I'm doing wrong or at least how to successfully customize devise views

P.S. Is it important to note that I changed the route of devise/registration#new to /signup?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

at a glance answer.

...instead of

rails generate devise:views User

use:

rails generate devise:views

If you've already done it, move the folders devise created from app/views/User to a new folder app/views/devise (or just rename the User folder to devise, if that's an option.)

Those folders are:

app/views/User/confirmations
app/views/User/mailer
app/views/User/passwords
app/views/User/registrations
app/views/User/sessions
app/views/User/shared
app/views/User/unlocks

No other changes are necessary.

Solution 2 - Ruby on-Rails

though this is an old question, I thought I'd add to it in case anybody stumbles on it. I'm not sure if this is a new addition since the question was originally asked but if so the simpler (more modern) approach is this.

in the file config/initializers/devise.rb there is the following block of code:

# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false

by uncommenting config.scoped_views = false and changing it's value to true, devise will automatically check whether the custom view exists and if so, serve that up. As it says it does add some overhead to the application but in my experience so far this is minimal.

Solution 3 - Ruby on-Rails

Your route signup or devise/registrations#new will render the view views/devise/registrations/new.html.erb. It sounds like you made changes to views/user/registrations/new.html.erb, which would explain why you dont see the changes made since its not being rendered.

You will either need to create a user/registrations_controller.rb that extends from Devise::RegistrationsController and point your /signup route to user/registrations#new, or you can just make your changes directly to views/devise/registrations/new.html.erb

Same idea applies to your login (devise/sessions) pages.

Hope this helps.

Solution 4 - Ruby on-Rails

For anyone still having a problem with this, the problem lies in the call to rails generate devise:views User. It should be rails generate devise:views for fetching current views from the Devise Rails Engine. This will generate proper views which will work with the default routes.

Solution 5 - Ruby on-Rails

After generating your custom views e.g

rails generate devise:views User

Turn on scoped_views in config/initializer/devise.rb

view config.scoped_views = true

And you are done.

Solution 6 - Ruby on-Rails

I had the same problem until I went back and read the devise documentation :)

After rails generate devise:views make sure you go into initializers/devise.rb and set config.scoped_views = true. This is explained in the devise documentation at https://github.com/plataformatec/devise as well as in the devise.rb comments.

After I did this, my own views in views/users started showing up instead of the ones in the gem.

Solution 7 - Ruby on-Rails

Using rails g devise:views User allows you to customize when you have more than one role.

the proper way to do this is going into your devise.rb in config/initializer/ folder

and uncommenting and setting config.scoped_views = true.

now you can edit the view erb files without any problems

Solution 8 - Ruby on-Rails

For future reference, you can just rename folder from devise => user and vice versa and rails will find a route.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVasseurthView Question on Stackoverflow
Solution 1 - Ruby on-RailsocodoView Answer on Stackoverflow
Solution 2 - Ruby on-RailsDazBaldwinView Answer on Stackoverflow
Solution 3 - Ruby on-RailsKevin TsoiView Answer on Stackoverflow
Solution 4 - Ruby on-RailsMarcus WView Answer on Stackoverflow
Solution 5 - Ruby on-RailsSaqib R.View Answer on Stackoverflow
Solution 6 - Ruby on-Railsguero64View Answer on Stackoverflow
Solution 7 - Ruby on-RailsRichard LauView Answer on Stackoverflow
Solution 8 - Ruby on-Railsuser1349666View Answer on Stackoverflow