Rails - where to store collections
I have many select options in my forms with a collection of possible options.
E.g.:
title_options = %w[Mr Mrs Miss Ms Dr]
In my view, I will render the select (using formtastic):
<%= f.input :title, :as => :select, :collection => title_options %>
Currently, though, I store the title options in a helper file with many
methods for each select:
module SelectHelper
def days_options
...
end
def title_options
...
end
..
end
Then, in a model for validation I can either extend this helper:
class user < ActiveRecord::Base
extend SelectHelper
validates :title, :inclusion => {:in => title_options}
end
or duplicate the options:
class user < ActiveRecord::Base
validates :title, :inclusion => {:in = %w[Mr Mrs Miss Ms Dr]}
end
Is there a better way to store the collection, for example, as a method in
the model directly? I don't see it necessary to store these options in a
database as they shouldn't ever change.
No comments:
Post a Comment