NoMethodError when trying to invoke helper method from Rails controller

To use the helper methods already included in the template engine:

  • Rails 2: use the @template variable.
  • Rails 3: has the nice controller method view_context

Example usage of calling ‘number_to_currency’ in a controller method:

# rails 3 sample
def controller_action
  @price = view_context.number_to_currency( 42.0 ) 
end

# rails 2 sample
def controller_action
  @price = @template.number_to_currency( 42.0 ) 
end

Leave a Comment