<%= collection_select :PriceRange, "7", PriceRange.where('value > 0'), :value, :name %>
* * * UPDATED EFFORTS * * *
난 또
@price_higher = PriceRange.find(7)
view, Controller 에 다루는 말했다
, {:selected => @price_higher.value}
내부의 collection_select. 이 전략은 덜 복잡한 방법을 찾고 있었던 것 같다고 할 수 있지만, 이 모든 일을 내 collection_select.
'선택한' 옵션을 추가합니다.
예:
collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:selected => "whatever_value"})
예) 에서 했다. 아피독
네 경우엔:
<%= collection_select :PriceRange, "7", PriceRange.where('value > 0'), :value, :name, {:selected => "whatever"} %>
기본 가치를 선택할 경우, 데이터 베이스 사용할
collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:selected => @authors.first})
그러면, 메시지 확인 하려면
collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => "Select Post"})