带有嵌套资源和 :find_by 的 CanCan gem
我使用 CanCan load_and_authorize_resource
辅助方法来获取资源和生成授权,但我有一个像这样的嵌套资源
load_and_authorize_resource :company
load_and_authorize_resource :accountings, :through => :company, :class => 'Departments::Accounting'
但我需要 @accountings 由另一个属性而不是 Departmets::Accounting id 找到,并为该属性提供一个值,例如
@accountings = @company.find_by_period_id(@period.id)
Im using CanCan load_and_authorize_resource
helper method for fetching resources and generating authorization, but I have a nested resource like this
load_and_authorize_resource :company
load_and_authorize_resource :accountings, :through => :company, :class => 'Departments::Accounting'
But I need
@accountings be found by another attribute rather that the Departmets::Accounting id and give a value to that attribute, for example
@accountings = @company.find_by_period_id(@period.id)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用两个额外选项来完成此操作:
检查
load_and_authorize_resource
的代码 这里。You can do it with two extra options:
Check the code for
load_and_authorize_resource
here.