开发者

rails CanCan: Fetching records with accessible_by and additional 'where' clause?

开发者 https://www.devze.com 2023-03-25 08:48 出处:网络
I am currently using the a开发者_C百科ccessible_by method of CanCan to fetch only relevant records of a model, which the logged-in user can access. So far, so good.

I am currently using the a开发者_C百科ccessible_by method of CanCan to fetch only relevant records of a model, which the logged-in user can access. So far, so good.

But how can I add to such a Foobar.accessible_by(current_ability) an additional 'where' clause?

I tried Foobar.accessible_by(current_ability).where(...), but that gives me an Exception: SQLite3::SQLException: ambiguous column name.


You're including a model that share the same attribute. If you want to use this attribute and keep the include you need to specify the model, e.g.:

Foo.include(:bar).where(:bar => { :name => 'xyz' })

This should be done in either your ability or in the .where(...), but that depends on the content of that ability and where.

0

精彩评论

暂无评论...
验证码 换一张
取 消