Reputation: 6486
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?
Upvotes: 83
Views: 90097
Reputation: 4305
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 the comment says, it may add some overhead to the application but in my experience so far, this is negligible.
Upvotes: 121
Reputation: 1049
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.
Upvotes: 14
Reputation: 589
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.
Upvotes: 25
Reputation: 1807
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.
Upvotes: 37
Reputation: 3069
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.
Upvotes: 22
Reputation: 696
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
Upvotes: 14
Reputation:
For future reference, you can just rename folder from devise => user and vice versa and rails will find a route.
Upvotes: 2
Reputation: 30248
at a glance answer.
rails generate devise:views User
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.
Upvotes: 127