Rails equivalent to Django's "choices"
On the validation side of things, probably validates_inclusion_of is what you need:
class Coffee < ActiveRecord::Base
validates_inclusion_of :size, :in => %w(small medium large),
:message => "%{value} is not a valid size"
end
As for generating the helper, you can try something like:
class Coffee < ActiveRecord::Base
@@coffe_size = %w(small medium large)
validates_inclusion_of :size, :in => @@coffe_size,
:message => "%{value} is not a valid size"
def self.coffee_size_options
@@coffe_size.map{ |z| [z,z]}
end
end
And then in some helper:
<%= select(:coffee, :size, Coffee.coffee_size_options) %>