I a, building a dropdown menu in a form that displays a list of available options and their prices in this form: "service - price". My problem, however, is that it doesn't look like I can use number_to_currency inside my controller. Is there another way to achieve the same effect, or to access number_to_currency from my controller? Here is my initial effort:
@levels = []
DistributorLevel.all.each do |d|
price = (d.price > 0) ? number_to_currency(d.price) : "Free"
@levels << ["#{d.name} - #{price}", d.id]
end
Yes, you could do with:
view_context.number_to_currency(d.price)
or
ActionController::Base.helpers.number_to_currency(d.price)
Try:
include ActionView::Helpers::NumberHelper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With