A default flag on a table in rails -
i have simple table/model in rails, vat_rates
. administrators need able select one, , 1 of these default rate selected on html form when creating new related items items have vat_rate_id
. have added boolean default
column vat_rates
table.
what straight forward, , rails-like way ensure 1 vat_rate
can default 1 @ time?
i'm not bothered if there no defaults, there no more one.
you add custom validation method this , return error if vat_rate selected default already. alternatively can add before_update or after_update callback this set other default values false on update.
Comments
Post a Comment