Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use helpers in rake?

Can I use helper methods in rake?

like image 468
Sam Kong Avatar asked Sep 20 '09 02:09

Sam Kong


People also ask

How do helpers work in Rails?

A helper is a method that is (mostly) used in your Rails views to share reusable code. Rails comes with a set of built-in helper methods. One of these built-in helpers is time_ago_in_words . This method is helpful whenever you want to display time in this specific format.


1 Answers

Yes, you can. You simply need to require the helper file and then include that helper inside your rake file (which actually a helper is a mixin that we can include).

For example, here I have an application_helper file inside app/helpers directory that contains this:

module ApplicationHelper   def hi     "hi"   end end 

so here is my rake file's content:

require "#{Rails.root}/app/helpers/application_helper" include ApplicationHelper  namespace :help do   task :hi do     puts hi   end end 

and here is the result on my Terminal:

god:helper-in-rake arie$ rake help:hi  hi 
like image 79
Arie Avatar answered Sep 29 '22 11:09

Arie