2014-03-19 31 views
0

我90%肯定,我做的事情顯然是錯誤的位置,但是當我使用的是選擇一個集合:選擇選項不formtastic現場使用收集驗證之後預選

<%= f.input :description, 
    :label => "Which best describes who you are?", 
    :prompt => "Select an option...", 
    :collection => [[ "I am working for a company", "working"],["I am a freelancer", "freelancer"],["I am studying", "studying"],["I have recently graduated", "graduated"],["I teach", "teach"],["None of these things","none"]] 
%> 

和表單未通過驗證,即使已保存並按預期方式將其傳遞到params [:user] [:description],也不會選擇先前選擇的值。任何想法,我要去錯了嗎?

回答

1

它的存在https://github.com/justinfrench/formtastic/wiki/Deprecation-of-%3Aselected-option#what-to-do-instead描述,所以下面應該工作

f.select :description, 
     options_for_select([[ "I am working for a company", "working"],["I am a freelancer", "freelancer"],["I am studying", "studying"],["I have recently graduated", "graduated"],["I teach", "teach"],["None of these things","none"]], f.object.description) 
     :label => "Which best describes who you are?", 
     :prompt => "Select an option...", 

此外,我會建議集合移動到一個單獨的輔助方法

+0

哦!感謝那。 – Daniel

+0

對不起,這沒有什麼區別:價值沒有預先選擇重新加載 – Daniel

+0

已更新取決於formtastic文檔 – MikeZ