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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.