How can I use scopes with Ransack in Rails 3?
问题 In my Widget model I have the following: scope :accessible_to, lambda { |user| if user.has_role?('admin') self.all else roles = user.roles role_ids = [] roles.each { |r| role_ids << r.id } self.joins(:widget_assignments).where('widget_assignments.role_id' => role_ids) end } Ideally, I would like to use this scope as a filter for Ransack's search results, so in my controller I have: def index @q = Widget.accessible_to(current_user).search(params[:q]) @widgets = @q.result.order('created_at DESC