0

在我的数据库中,我有 3 个字段:

name, cost, active

我如何才能在选择(表单)中仅显示那些活动字段为真(1)的值?现在我有这样的代码:

= f.select :shipping_id, [["Select", "0"]] + @shippings.map{ |c| [c.name, c.id]}, {:required => true}

如何映射,仅当 active 为 true 时?

笔记!我必须只在眼前这样做!

4

2 回答 2

1

尝试:

@shippings.select{|s| s.active}.map{|c| [c.name,c.id]}
于 2013-01-11T11:09:30.787 回答
0

在你的控制器中

@shippings = Shipping.where(:active => 1)
于 2013-01-11T11:31:38.540 回答