ruby on rails - Trouble on `validates_inclusion_of` using radio buttons -
i using ruby on rails 3.0.7 , have problem on using validates_inclusion_of
method.
i model file have:
class user < activerecord::base inclusion_values = ['beautiful', 'ugly', 'good', 'bad'] validates :test, :inclusion => { :in => user::inclusion_values } end
in view file have
<%= form_for(@user) |f| %> <% user::inclusion_values.each |test| %> <%= f.radio_button :test, test %> <% end %> <% end %>
the above "view" code generate this:
<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">
whatever submitting form gives me validation error:
test not included in list
how can solve issue?
i tryed use (as described here in note above page)
%w(beautiful, ugly, good, bad)
and validates_inclusion_of
format
validates_inclusion_of :test, :in => user::inclusion_values
or
validates :test, :inclusion => user::inclusion_values
but validation error.
solution (dho!)
i forget make attribute attr_accessible
!
Comments
Post a Comment