在我的Ruby on Rails应用程序中,我使用设计来验证"管理员"。
我只使用"管理员"模型,所以我修改了' routes.rb'用于定义网站自定义路由的文件
的routes.rb
Rails.application.routes.draw do
resources :contacts
devise_for :admins
#Personal Devise admin routes
as :admin do
#Session Block
get "/login" => "devise/sessions#new", :as => :admin_session_login
delete "/logout" => "devise/sessions#destroy", :as => :admin_logout
#Account Block
get "/register" => "devise/registrations#new", :as => :admin_register
get "/edit_account" => "devise/registrations#edit", :as => :admin_edit
end
end
我保存了文件并重新启动了服务器但是当我尝试导航到其中一条自定义路线时,例如' / login'该应用程序将我重定向到http://localhost:3000/
当我尝试导航到/ login时,我也会发布服务器控制台日志:
控制台服务器日志
Started GET "/login" for 127.0.0.1 at 2015-06-29 18:15:32 +0200
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Devise::SessionsController#new as HTML
Admin Load (0.3ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = ? ORDER BY "admins"."id" ASC LIMIT 1 [["id", 1]]
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 46ms (ActiveRecord: 0.9ms
)
答案 0 :(得分:0)
我无法添加评论。 如果已登录,则始终会将您重定向到root_path。你可以尝试另一条路来找出答案。
答案 1 :(得分:0)
更改默认设计重定向路径只需添加此方法
在您的应用程序控制器中
def after_sign_in_path_for(resource)
yourpathname_path(resource)
end