1
我正在使用Ruby on Rails 3.0.7,並且在使用validates_inclusion_of
方法時遇到問題。使用單選按鈕在`validates_inclusion_of`上遇到問題
我在我的模型文件我有:
class User < ActiveRecord::Base
INCLUSION_VALUES = ['beautiful', 'ugly', 'good', 'bad']
validates :test,
:inclusion => {
:in => User::INCLUSION_VALUES
}
end
在我看來,文件我有
<%= form_for(@user) do |f| %>
<% User::INCLUSION_VALUES.each do |test| %>
<%= f.radio_button :test, test %>
<% end %>
<% end %>
上述 「意見」 的代碼生成此:
<input type="radio" value="beautiful" name="user[test]" id="user_test_beautiful">
<input type="radio" value="ugly" name="user[test]" id="user_test_ugly">
<input type="radio" value="good" name="user[test]" id="user_test_good">
<input type="radio" value="bad" name="user[test]" id="user_test_bad">
無論我做什麼提交給我的驗證錯誤的表單:
Test is not included in the list
我該如何解決問題?
我還tryed使用(作爲網頁上面的說明中描述here)
%w(beautiful, ugly, good, bad)
和validates_inclusion_of
格式
validates_inclusion_of :test, :in => User::INCLUSION_VALUES
或
validates :test, :inclusion => User::INCLUSION_VALUES
但我總是得到驗證錯誤。