Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't override default devise gem views

I want to use my devise generated views (with command rails g devise:views users) from app/views/users.

I already have set these options from app/initializers/devise.rb:

config.scoped_views = true
config.default_scope = :user

but it still uses default devise views from /usr/lib/ruby/gems/1.8/gems/devise-2.0.4/app/views/devise/

So what should I do? Thanks.

like image 783
user973254 Avatar asked Feb 24 '12 15:02

user973254


People also ask

What is devise gem?

Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).


2 Answers

I was having this same problem and it took me forever to figure it out. Setting config.scoped_views = true is the first step, but there's another step that's not as clear.

If you look closely at some of the views that get generated by rails g devise:views users you'll see that the templates include <%= render "devise/shared/links" %> at the bottom of the file. Since you have generated these views, the shared links are now located in users/shared/links. Since devise doesn't find anything in devise/shared/links anymore, it uses the default links view instead.

Change <%= render "devise/shared/links" %> to <%= render "users/shared/links" %>and you're set!

like image 154
dpcasady Avatar answered Oct 07 '22 18:10

dpcasady


For a custom login view, when you're using the default User devise resource, I think all you need is to create app/views/devise/sessions/new.html.erb. And, just for the moment, let's forget about the CRUD interface. And undo those config/initializers/devise.rb settings. Just see if you can get that working.

like image 42
Tom L Avatar answered Oct 07 '22 20:10

Tom L