If I have a model where one attribute can be set only to several predefined values, like this:
class Painting < ActiveRecord::Base
SALE_STATUS = ["for sale", "sold"]
validates_inclusion_of :status, :in => SALE_STATUS
end
Is there a way to write an ERb/HTML form so that the input field for status would only display something like a radio button or checkbox for each of the available options?
<%= form_for @painting do |painting| %>
<%= painting.check_box :status # ... don't know how to implement!
<% end %>
Thanks for your time.
I think you could do something like this:
But this code allow the user to choose none of the Sale Status. If you want to allow null values for the status, add this to your model:
If not, use radio buttons instead: