我如何在耙子中使用助手? [英] How do I use helpers in rake?

查看:110
本文介绍了我如何在耙子中使用助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在耙中使用辅助方法吗?

Can I use helper methods in rake?

推荐答案

是的,可以.您只需要需要帮助程序文件,然后将该帮助程序包含在rake文件中(实际上,该帮助程序是我们可以包含的mixin).

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).

例如,在这里,我在 app/helpers 目录中有一个 application_helper 文件,该文件包含以下内容:

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

module ApplicationHelper
  def hi
    "hi"
  end
end

这是我的rake文件的内容:

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

这篇关于我如何在耙子中使用助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆