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.
精彩评论