我有這樣一行:從Ruby on Rails中的collection.map排除選項?
<%= f.input :state_id, :input_html => {:value => (policy_address.state.name rescue nil)}, :required => true, :collection => states.map {|s| [ s.name, s.id] }, :include_blank => 'Please select'%>
我想排除從states.map
收藏價值。我認爲這會工作,但它並不:
<%= f.input :state_id, :input_html => {:value => (policy_address.state.name rescue nil)}, :required => true, :collection => states.map {|s| [ s.name, s.id] unless s.name == "excluded_state" }, :include_blank => 'Please select'%>
我把unless s.name == "excluded_state
,但同樣,它不工作:
我在做什麼錯?
謝謝!完美工作 – Ryan
這正是我需要的。謝謝 –
'states.map {| s | [s.name,s.id] if s.name ==「excluded_state」} .compact' –