Rails3 Active Admin:如何在首次点击Shipments标签时仅显示打开状态记录?

我正在使用ActiveAdmin。 我有一份包含打开和关闭状态(作为字符串)的货件清单。 当用户点击“货件”选项卡时,我只想显示“打开”货件。 我怎样才能做到这一点? 当然,用户以后可以选择使用filter查看已关闭的货件。 但我希望默认情况下最初只显示Open货件。

可能最好的方法是在模型中创建范围。 AA自动获取您的范围并在索引视图中创建表格上方的选项卡。 请记住在app / admin / your-resource-name.rb文件中添加范围。

#app/models/shipments.rb scope :opened, where(:status => "Open") scope :closed, where(:status => "Closed") 

…并将范围添加到资源文件中

 #app/admin/shipments.rb scope :opened scope :closed 

我没时间测试,但它应该工作。

具有简单范围的ASCIIcast: http ://asciicasts.com/episodes/284-active-admin

模型中的范围:

 #app/models/shipments.rb scope :opened, where(:status => "Open") scope :closed, where(:status => "Closed") 

activeadmin资源中的作用域,标记为默认值:

 #app/admin/shipments.rb scope :opened, :default => :true scope :closed