簡體   English   中英

Ruby選擇選項if語句

[英]Ruby select options if statement

在我的數據庫中,我有3個字段:

name, cost, active

我如何僅在選擇(窗體)中顯示活動字段為true(1)的值? 現在我有這樣的代碼:

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

僅當active為true時才如何映射?

注意! 我必須只在視野范圍內這樣做!

嘗試:

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

在您的控制器中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM