我在"Rails Root"/lib/tasks/example.rake
下面的代码中定义一个定制类中:Rails和Rake任务 - 如何调用一个Rails方法耙子任务文件
task :example_task => :environment do
e = Example.new
e.example_method
end
class Example
def example_method
select_tag 'Example'
end
end
当我在rake任务调用e.example_method
,我得到错误"undefined method 'select_tag' for #<Example:0x39f58b0>"
。
select_tag
是Rails方法:http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-select_tag
如何让select_tag
电话的工作?
你只需要要求您需要的帮手。请检查这个[问题] [1]。 [1]:http://stackoverflow.com/questions/1450112/how-do-i-use-helpers-in-rake –
'select_tag'是在'ActionView'为什么助手方法之一您的Rake Task会调用与视图相关的任何方法吗?只是好奇 –