【发布时间】:2021-02-03 23:23:15
【问题描述】:
我看过很多关于如何在设计中重命名已声明的路由的帖子。我想扩展设计以进行自己的路线检查和空闲会话。我每 1 分钟执行一次简单的 js 检查,我想在设计会话控制器中点击“check_active”。我试过了,但没有运气:
devise_scope :sessions do
get 'check_active'
end
有没有办法扩展自定义路线(不是重命名已经存在的路线)?
更新 - 快到了,我做到了
# already had this in routes
devise_for :users, :controllers =>
{ registrations: 'registrations',
confirmations: 'confirmations',
sessions: 'sessions',
passwords: 'passwords',
omniauth_callbacks: "omniauth_callbacks"}
# added this
devise_scope :sessions do
get '/check_active' => 'sessions#check_active'
end
我有一个 js 触发,我让它得到 '/check_active',因为 rake 路由显示如下:
check_active GET /check_active(.:format)
但是当它触发时,控制器 404s 与
AbstractController::ActionNotFound(找不到路径“/check_active”的设计映射。
这可能有两个原因:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
get "/some/route" => "some_devise_controller"
end
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
):
【问题讨论】:
-
你在 session_controller 中创建了 check_active 方法对吧?
标签: ruby-on-rails devise