Second devise model not using generated views

只谈情不闲聊 提交于 2020-01-31 18:12:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!