一般而言,使用 gem devise 进行用户认证时,在控制器中,增加一句“before_action :authenticate_user!”就可以实现目的。但是当控制器中存在模块引用“include ActionController::Live”时,会抛出“uncaught throw :warden devise”错误,去掉该模块引用“include ActionController::Live”,该错误消失。
###问题解决: 经过谷歌查询,得到的解决方案是,将路由包装在块中,解决“uncaught throw :warden devise”错误,即: 之前路由:
resources :docfiles do
collection do
delete :destroy_files
post :download_files
end
member do
delete '/files/:file_id' => 'docfiles#destroy_file', as: :destroy_file
end
end
将路由包装在块中后的路由:
authenticate do
resources :docfiles do
collection do
delete :destroy_files
post :download_files
end
member do
delete '/files/:file_id' => 'docfiles#destroy_file', as: :destroy_file
end
end
end
通过以上方案,问题解决。 具体参见:https://github.com/heartcombo/devise/issues/2332