1

I'm having a hard time including some view helpers in a file thats in /lib, say I have this:

module TwitterPost
  include ActionView::Helpers::NumberHelper

  def update
    number_with_delimiter(1234567)
  end
end

I get:

NoMethodError: undefined method `number_with_delimiter' for TwitterPost:Module

But in my console, I'm able to just include ActionView::Helpers::NumberHelper and then I'm able to just do number_with_delimiter(1234567) and it works just fine.

Why is this? I need to include ActionView::Helpers::NumberHelper in a bunch of different models as well but I've had no luck in getting it to work.

JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
  • You can refer to my answer here http://stackoverflow.com/questions/4467697/rails-why-the-number-with-delimiter-method-is-not-recognized-inside-my-model/25979370#25979370 – Le Duc Duy Sep 22 '14 at 17:02

1 Answers1

7

I think you may be mixing up how Modules work.

You need to mix the module into a class for the instance methods to work.

module TwitterPost
  include ActionView::Helpers::NumberHelper

  def update
    number_with_delimiter(1234567)
  end
end

class Foo
  include TwitterPost
end

foo = Foo.new
foo.update
   => "1,234,567" 
Gazler
  • 83,029
  • 18
  • 279
  • 245