我想用自己的页面代替 devise 的 sign_in 页面
我尝试了自己写了个 devise/sessions/new.html.erb 页面,不过他读取的是默认的 application_controller
如果我想放到 admin 的 namespace 下面呢? routes.rb :
namespace :admin do
devise_for :accounts
end
会报这个错误
No route matches {:action=>"new", :controller=>"devise/sessions"}
根据https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes 修改了 routes.rb
devise_for :accounts, :controllers => {:sessions => 'accounts/sessions'}, :skip => [:sessions] do get 'signin' => 'accounts/sessions#new', :as => :new_account_session post 'signin' => 'accounts/sessions#create', :as => :account_session get 'signout' => 'accounts/sessions#destroy', :as => :destroy_account_session end
现在跟我说 undefined method `authenticate_account!' for #Admin::CategoriesController:0x007fdb93e51908
用自己的页面代替默认登陆页面 我用自己的项目给楼主写个例子吧 楼主想为 Account 进行 devise routes.rb
devise_for :accounts, :controllers => { :sessions => "admin/sessions" }
然后将 sessions_controller.rb 拷贝到如下目录
app/controllers/admin/
同时新建以下 view
app/views/admin/sessions/new.html.erb #登陆页面
当然楼主可以把其他的页面也搬过来
贴一下路由信息
$ rake routes
new_account_session GET /accounts/sign_in(.:format) {:action=>"new", :controller=>"admin/sessions"} #登陆
account_session POST /accounts/sign_in(.:format) {:action=>"create", :controller=>"admin/sessions"} #新建
destroy_account_session DELETE /accounts/sign_out(.:format) {:action=>"destroy", :controller=>"admin/sessions"} #注销
用 devise_scope
devise_scope :user do
get "login", :to => "devise/sessions#new"
get "register", :to => "devise/registrations#new"
get "logout", :to => "devise/sessions#destroy"
get "profile", :to => "devise/registrations#edit"
end
这个问题解决了 https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L94 这里面有提到,把 authenticate_account 改成 authenticate_admin_account