使用formtastic字段中的集合验证后选择未预选的选项

时间:2014-03-19 17:32:37

标签: ruby-on-rails formtastic

我90%肯定我在这里做了一些明显错误的事情,但是当我使用带有集合的选择时:

<%= 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"]] 
%>

并且表单未通过验证,即使已保存并正按预期传递给参数[:user] [:description],也不会选择先前选择的值。我出错了什么想法?

1 个答案:

答案 0 :(得分: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...", 

另外我建议将集合移到单独的帮助方法