Possible duplicate:Access to view assistant for model in rails
I know that this is probably not something I should do often, but I want to use an assistant within the model.
I am creating a spreadsheet in the Report model and would like to use the time_ago_in_words method in ActionView::Helpers::DateHelper
time_ago_in_words
ActionView::Helpers::DateHelper
Is this doable, or should I generate it in a view?
You can simply include the module in the model and use it in the same way as in the view
class Report include ActionView::Helpers::DateHelper ... end
class Post < ActiveRecord::Base include ActionView::Helpers::DateHelper def my_test_method(a, include_seconds = false) time_ago_in_words(a, include_second) end end
Source: https://habr.com/ru/post/893515/More articles:Problem using Google Analytics with Require.js - javascriptSQL optimization and disjunctive normal form - sqlHow can I compile automatically generated C files in pre-build? - cwpf: how to handle KeyDown event for Datagrid? - eventsDoes Google+ have an open API? - google-plusLINQ - how to get the next three business days excluding dates in the table? - linqBean start not called - java-eeXcode - How could you copy paste classes / files from one project to another? - xcodeSDL / OpenGL: implementation of the "boot stream" - c ++Access to view assistant for model in rails - ruby-on-railsAll Articles