number-with-delimiter

Rails: Why is the “number_with_delimiter” method not recognized inside my model?

China☆狼群 提交于 2020-01-21 04:36:08
问题 I have a simple validation: class Product < ActiveRecord::Base # include ActionView::Helpers::NumberHelper ... validates_numericality_of :price, :less_than => 1000000, :message => "must be less than #{number_with_delimiter(1000000)}" ... end On this code, I have received the following error: undefined method `number_with_delimiter' for #<Class:0x2665a58> I tried to add: include ActionView::Helpers::NumberHelper but it didn't help. What am I missing? 回答1: The true problem here is that you're

number_with_precision return Integer

为君一笑 提交于 2020-01-06 07:44:53
问题 I have a very weird problem with number_with_precision() and number_to_currency() . In my application, they both raise an comparison of String with 0 failed if i do not set :precision But when i try the very same functions in irb, everything is fine : 1.9.3p0 :058 > helper.number_with_precision(12) => "12.000" 1.9.3p0 :059 > helper.number_to_currency(12) => "12.00 €" I looked in to my Gemfile, guessing it could be coming from one of my Gem, but i did not find anything. I have the strange