0

どうやって書くのが一番いいかわからない。乾杯!

def get_prices(c)
  @print_prices = Billing.where(:name => c).first.attributes.select{ |i| i.match(/^print_/) }
end
4

2 に答える 2

2

それを行う1つの方法:

def get_prices(c)
  billings = Billing.where(:name => c)
  @print_prices = billings.first.attributes.select{ |i| i.match(/^print_/) } unless billings.empty?
end
于 2012-10-31T00:02:18.857 に答える
1

の戻り値を保存してBilling.where(:name => c).firstテストする必要があります。

于 2012-10-31T00:03:00.480 に答える