我正在使用ActiveAdmin。我有一份包含打开和关闭状态(作为字符串)的货件清单。当用户点击“货件”选项卡时,我只想显示“打开”货件。我怎样才能做到这一点?当然,用户以后可以选择使用过滤器查看已关闭的货件。但我希望默认情况下最初只显示Open货件。
答案 0 :(得分:2)
可能最好的方法是在模型中创建范围。 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
答案 1 :(得分:2)
模型中的范围:
#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