如何將一個這樣做:Rails 3:Text_field_tag默認值如果參數[:something] .blank?
= f.input_field :age,
:collection => 18..60,
:id => 'age',
:selected => params[:age].blank? or "20"
以上doesen't工作。如果無參數可用於該屬性,我希望能夠設置默認值。
任何智能的方法來做到這一點!
編輯1: 賽程表:
= simple_form_for :people, :url => request.fullpath, :method => :get, :html => { :class => 'form-search' } do |f|
#container_search_small.form-search
= f.input_field :age,
:collection => 18..60,
:id => 'age',
:selected => params[:people][:age_from] || "20"
= f.submit "Go »"
try params [:age] || 「20」 – Amar
我認爲JavaScript應該用於設置默認值 –
應該可以使用以下參數設置值:基於參數選擇但是如果參數未提交失敗。我得到一個未定義的方法'[]'零:NilClass – Rubytastic