简体   繁体   中英

Ruby select options if statement

In my db i have 3 fields:

name, cost, active

How can i display in select (form) only that values, on which active field is true(1)? Now i have such code:

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

How to map, only if active is true?

Note! i must done it only in view!

尝试:

@shippings.select{|s| s.active}.map{|c| [c.name,c.id]}

在您的控制器中

@shippings = Shipping.where(:active => 1)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM