How can I add a scope just for some actions on ActiveAdmin
activeadmin, ruby-on-rails
Solution
You can call super for other action on which you don't want your `scoped_collection` to be called.
ActiveAdmin.register Post do
controller do
def scoped_collection
if ['index', 'action2', 'action3'].include?(params[:action])
current_user.posts
else
super
end
end
end
end
Problem
I have a classic posts-belongs-to-user association. I want to apply a default_scope to all the actions like `#index` so it lists my posts only. But I want the ability to see posts from anybody when I go to the `#show` action if follow a link to it. How can I avoid the default_scope to be applied on that action? ``` class Post < ActiveRecord::Base belongs_to :user end ActiveAdmin.register CertificationModel do controller do def scoped_collection current_user.posts end end end ```