I'm using ActiveAdmin. I have a list of Shipments with status (as a string) of Open and Closed. When the user clicks on the Shipments tab, I want to display only the Open shipments. How can I do that? Of course, the user could later choose to see the Closed shipments by using the filter. But I want the default to initially only show the Open shipments.
Probably best way will be to create scopes in model. AA automatically gets your scopes and creates tabs above table in index view. Remember to add scopes in app/admin/your-resource-name.rb file.
#app/models/shipments.rb
scope :opened, where(:status => "Open")
scope :closed, where(:status => "Closed")
... and add scopes to resource file
#app/admin/shipments.rb
scope :opened
scope :closed
I don't have time to test, but it should work.
ASCIIcast with simple scope: http://asciicasts.com/episodes/284-active-admin
scopes in the model:
#app/models/shipments.rb
scope :opened, where(:status => "Open")
scope :closed, where(:status => "Closed")
scopes in the activeadmin resource, one marked as default:
#app/admin/shipments.rb
scope :opened, :default => :true
scope :closed
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.