[Ruby on Rails] How to use helper methods in controllers and models

Tadashi Shigeoka ·  Wed, December 12, 2012

I researched how to use helper methods in controllers and models in Ruby on Rails, so here are my notes.

Simply write include ActionView::Helpers.

When you don’t need all helpers, you can specify them like this:

class Bill < ActiveRecord::Base
  include ActionView::Helpers::NumberHelper

  def hoge
    number_with_delimiter 1234
  end
end

【References】

ruby on rails - Using helpers in model: how do I include helper dependencies? - Stack Overflow

モデルからヘルパーを使う - 主に Ruby On Rails のこと

That’s all from the Gemba.