ruby on rails - Where to hold important lists -
my app has numerous lists of options that, example, govern stage project @ - these options users choose select list. have many of these , i'm running organization problem, namely define these in 1 place system stays dry.
i'm wary of generating lots of polymorphic tables in interests of normalization, complicate code quite bit without adding in way of real value.
can give me example of store options 1) options possible field, , 2) available in form system-wide?
i use symbolize gem kind of scenario. can store field options strings, perform operations on model values symbols, use i18n labels, , there's set of helpers build selects based on options.
also, code kept clean, since set available options on model itself.
check out:
https://github.com/nofxx/symbolize
here's sample documentation:
class user < activerecord::base symbolize :gender, :in => [:female, :male], :scopes => true symbolize :so, :in => { :linux => "linux", :mac => "mac os x" }, :scopes => true # allow blank symbolize :gui, :in => [:gnome, :kde, :xfce], :allow_blank => true # don`t i18n symbolize :browser, :in => [:firefox, :opera], :i18n => false, :methods => true # scopes symbolize :angry, :in => [true, false], :scopes => true # don`t validate symbolize :lang, :in => [:ruby, :c, :erlang], :validate => false # default symbolize :kind, :in => [:admin, :manager, :user], :default => :admin end
Comments
Post a Comment