Rails3 Active Admin:第一次单击Shipments标签时如何仅显示打开状态记录? [英] Rails3 Active Admin: How to display only Open status records when first click on Shipments tag?

查看:62
本文介绍了Rails3 Active Admin:第一次单击Shipments标签时如何仅显示打开状态记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ActiveAdmin。我有状态为(字符串形式)打开和关闭的货件清单。当用户单击货件选项卡时,我只想显示未清货件。我怎样才能做到这一点?当然,用户以后可以使用过滤器选择查看已关闭的货件。但是我希望默认值最初只显示未清装运。

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.

推荐答案

模型范围:

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

activeadmin资源中的范围,一个标记为默认范围:

scopes in the activeadmin resource, one marked as default:

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

这篇关于Rails3 Active Admin:第一次单击Shipments标签时如何仅显示打开状态记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆