我一直在使用rails_admin v0.7.0和clearance gem成功達到這一點。我試圖今天將rails_admin更新爲v1.0,但我得到了一個未定義的變量或方法錯誤current_user
。在v0.7.0中,似乎RailsAdmin::MainController
繼承自ApplicationController
,而在v1.0中它直接繼承自ActionController::Base
,這可以解釋current_user
現在是不確定的(我相信current_user
在ApplicationController
中與間隙寶石一起定義)。然而,由於我沒有發現任何其他人有這個問題,我想我一定是錯過了一些東西。'current_user'undefined在rails_admin中有許可權
我不是那個在這個應用程序中設置清除的人,但我認爲我們不會對它做任何不符合標準的事情,這會影響到這一點。 Clearance::Controller
包含在ApplicationController
中。 current_user
沒有特別的定義。
配置/初始化/ rails_admin.rb
RailsAdmin.config do |config|
# Popular gems integration
## Clearance
config.authorize_with do |controller|
unless current_user.admin?
redirect_to(
main_app.root_path,
alert: "You are not permitted to view this page"
)
end
end
config.current_user_method { current_user }
end
'rails_admin'問題的最佳答案。 –
我需要這個與Rails 5應用程序中的Sorcery集成,謝謝! –
我在這個問題上摔跤了*小時*。謝謝! – daybreaker