监狱长回调应放在rails应用程序中? [英] Where should warden callbacks be placed in a rails app?
问题描述
查看 Warden wiki页面,我可以使用after_set_user回调来执行此逻辑,例如:
Warden :: Manager.after_set_user do | user,auth,opts |
除非user.active?
auth.logout
throw(:warden,:message =>用户不活动)
end
end
但是,我不知道我应该在哪里存储这些东西。我的第一个想法是,我可以把它放在config / initializers / devise.rb中。那是对的吗?在配置目录中不要把本质上的控制器代码放在正确的位置。
应用程序正在引导,所以Devise的初始化程序在config / initializers / devise.rb里面是一个很好的候选人。
然而,要实现的行为将更好地通过使用这个Devise功能:
I'm relatively new to rails. I have Devise set up, and want to run some callback code after users sign in.
Looking at the Warden wiki page, I can use the "after_set_user" callback to perform this logic, for example:
Warden::Manager.after_set_user do |user, auth, opts|
unless user.active?
auth.logout
throw(:warden, :message => "User not active")
end
end
However, I'm not sure where I should be storing this stuff. My first thought is that I could put it in config/initializers/devise.rb. Is that correct? It doesn't feel right putting what is essentially controller code in the config directory.
Warden hooks need to be required when your application is booting, so inside Devise's initializer at config/initializers/devise.rb is a good candidate.
However, the behavior you want to achieve will be better accomplished by using this Devise feature:
这篇关于监狱长回调应放在rails应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!