这是我解决这个问题的方法..
# /RAILS_ROOT/lib/app_name/currency_helper.rb
module AppName
module CurrencyHelper
include ActionView::Helpers::NumberHelper
def number_to_currency_with_pound(amount, options = {})
options.reverse_merge!({ :unit => '£' })
number_to_currency_without_pound(amount, options)
end
alias_method_chain :number_to_currency, :pound
end
end
in your models you can do this (and you won't be polluting your model with methods you aren't going to use)
class Album < ActiveRecord::Base
include AppName::CurrencyHelper
def price
currency_to_number(amount)
end
end
then for your views to all be updated include the module in one of your app helpers
module ApplicationHelper
# change default currency formatting to pounds..
include AppName::CurrencyHelper
end
Now everywhere you use the number to currency helper it will be formatted with a pound symbol, but you also have all the flexiblity of the original rails method so you can pass in the options as you did before ..
number_to_currency(amount, :unit => '$')
will convert it back to a dollar symbol.