开发者

Can you change Multiple Properties with select helper?

开发者 https://www.devze.com 2023-03-20 14:37 出处:网络
I\'m using th开发者_如何学Goe following select helper: f.select(:page_color, Orders::PAYMENT_TYPES ,:prompt => \"Select a Box\")

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

精彩评论

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