开发者

Can you change Multiple Properties with select helper?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜