2
我使用simple_form表單並傳遞一些URL參數 預填充表單。Rails的simple_form服務器端驗證丟失的URL參數
此代碼確定
<%= f.input :first_name, :label => 'First Name', :input_html => { :value => params['first'] } %>
使用URL
http://localhost:3000/charities/new?first=Bob
,輸出這個HTML
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" value="Bob" />
但是如果表單服務器端驗證失敗的頁面重新加載,但預填充 價值不復存在?這是在渲染HTML
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" />
誰能幫告知如何預填充simple_form,如果服務器端validastion失敗並重新加載頁面保留這些 值?
謝謝。如果你想使之與驗證工作,你應該預設對象值控制器這樣
相關的'form_tag':http://stackoverflow.com/questions/4129229/rails-restoring非模型形式 - 使用形式標籤 –