问题
I have a User and a Rep model
devise_for :users, :controllers => {:registrations => 'user_registration'}
devise_for :reps
I ran
rails generate devise:views reps
The custom views show up in app/views/reps
But the rep paths are still using the built in devise views
Rendered ~/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.9/app/views/devise/registrations/edit.html.erb
Instead of the generated reps views.
回答1:
By simply putting the views there Devise won't use them. You would need to point Devise::RegistrationsController
to the right controller which has these views, which you can do by calling this:
devise_for :reps, :controllers => { :registrations => "reps/registrations" }
This needs to have a new controller defined at app/controllers/reps/registrations_controller.rb
:
class Reps::RegistrationsController < Devise::RegistrationsController
end
You would then have the views in the right directory for this controller to use.
回答2:
I had the same problem. I eventually spotted this in the documentation.
If you have more than one role in your application (such as “User” and “Admin”), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set “config.scoped_views = true” inside “config/initializers/devise.rb”.
So I switched the config.scoped_views to true and it worked a charm :)
回答3:
I actually had the same problem and I realized that the model names are case sensitive. I used the command
rails generate devise:views Admins
Instead of
rails generate devise:views admins
and it created the folder at '/app/views/Admins' but was looking for the custom view in 'app/views/admins'
来源:https://stackoverflow.com/questions/8320398/second-devise-model-not-using-generated-views