I'm using th开发者_如何学Goe following select helper:
f.select(:page_color, Orders::PAYMENT_TYPES ,:prompt => "Select a Box")
is it possible to change multiple columns with one selection? Say I want to change :page_color and :pay_method with the selection of "Check". Is this possible?
PAYMENT_TYPES = [
# Displayed stored in db
[ "Check", "check" ],
[ "Credit card", "cc" ],
[ "Purchase order", "po" ]
]
I think the cleanest thing would be to write a virtual attribute:
def paymethod=(value)
mapping = {
'check' => 'red',
'cc' => 'green',
...
}
self.page_color = mapping(value)
super
end
精彩评论