次のようなコードがあります。
number_to_currency(line_item.price, :unit => "£")
さまざまなモデルで私の見解を散らかしています。私のアプリケーションは GBP (£) のみを扱っているため、これを各モデルに移動して、本来line_item.price
あるべき文字列を返すようにすべきではありません (つまりnumber_to_currency(line_item.price, :unit => "£")
、line_item.price
同じです。これを行うには、次のようにする必要があると考えています:
def price
number_to_currency(self.price, :unit => "£")
end
しかし、これは機能しません。モデルで がすでに定義されている場合、 Railsprice
は「スタック レベルが深すぎます」と報告します。def price
def amount
number_to_currency