has many - what is the right way to model status values as an association in Rails? -
i have model called contacts.
contacts can have different status "bad, positive, wrong..."
these status may need changed on time, across contacts, same options.
should model way:
contacts.rb belongs_to :status_contact statuscontacts.rb has_many :contacts then manually populate types of status in table?
i want use ajax click button corresponding value update value contacts.
it looks you're trying ensure values status going restricted set of possible answers of choosing. if that's you're trying do, there's no special need separate table. can use magic of activerecord validations instead here.
first, create string database column contact called :status.
then can use validation ensure values limited ones want. in rails 3, can this:
validate :status, :inclusion => { :in => %w( bad positive wrong ) } (if you're using rails 2, use #validates_inclusion_of instead.)
in activerecord, validations check object's values valid before saving; refuses persist object database until validations pass.
Comments
Post a Comment