开发者

Rails 3, Cancan, Multiple model searching with accessible_by

I have an issue where I'm using cancan's accessible_by to return authorized Announcements, Resources, etc (based on a subject_id for a specific announcement, resource, etc). I would like to be able to search all of these models for various criteria and have the result set come back with only the valid and authorized results to allow for pagination, ordering, etc.

I'm honestly a bit lost on how to best approach this. At first I thought maybe I could do a polymorphic table "Search" that stores various attributes from each type of model (basically an indexing table), but it seems I can't really authorize the base models at that point.

Any help would be appreciated, or thoughts on a better approach. The only real requirements are sort of a "global search" of the content in the app where only the current use开发者_如何学Pythonr's authorized results are returned.


In Rails3, since relational operators return relations, they can be further chained.
In a controller action:

Model.accessible_by(current_ability).where('name LIKE "%?%"', params[:search])
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜