Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a Rails helper in a model [duplicate]

Possible Duplicate:
Access a view helper for a model in rails

I know this is probably not something I should do often, but I want to use a helper within a model.

I'm generating a spreadsheet in a Report model and would like to use the time_ago_in_words method in ActionView::Helpers::DateHelper

Is this doable, or should I be generating it in a view?

like image 866
Joe Flynn Avatar asked Jul 25 '11 18:07

Joe Flynn


1 Answers

You can just include the module in the model, and use it like you would in a view

class Report
  include ActionView::Helpers::DateHelper
  ...
end
like image 172
Joe Flynn Avatar answered Oct 06 '22 16:10

Joe Flynn