Reputation: 1369
Using active admin with ActiveRecord scopes was explained here: Rails3 Active Admin: How to display only Open status records when first click on Shipments tag?
Now I'm trying to do it for a scope with params.
In my model i have:
#app/models/shipments.rb
scope :by_status, -> (status) { where(status: status) }
I want to be able to use this in app/admin/shipments.rb
to be something like
# app/admin/shipments.rb
scope :by_status 'open'
Is there an active admin way to do that?
Upvotes: 5
Views: 1955
Reputation: 700
You can use a block:
scope :open do |shipments|
shipments.by_status('open')
end
If you want this to be the default scope:
scope :open, default: true do |shipments|
shipments.by_status('open')
end
Upvotes: 9