我正在寻找如何设置我的 :notice 以合并一个辅助方法,目前我有这个并得到“未定义的方法 to_dollars”:
notice: "Thank you for your payment of #{to_dollars(amount)}"
控制器
def create
@donation = @campaign.donations.create(donation_params)
if @donation.save_with_payment
amount = @donation.donation_amount
redirect_to @campaign, notice: "Thank you for your payment of #{to_dollars(amount)}"
else
flash[:notice] = @donation.errors
render :new
end
end
我的辅助方法很简单(除非有人有更好的方法)
def to_dollars(amount)
convert = amount / 100
number_to_currency(convert, unit: "$", separator: ".", delimiter: "")
end
所有的捐赠金额都以美分保存,因此只想将它们转换为美元。