我在rails应用程序中有rake任务.我想在rake任务中运行命令行命令.我怎样才能做到这一点.我试过以下但失败了
desc "Sending the newsletter to all the users"
task :sending_mail do
run "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v"
system "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v &"
end
Run Code Online (Sandbox Code Playgroud)
上面的run命令抛出run方法undefined&System命令没有抛出任何错误但没有执行.
我有以下Rake任务:
namespace :foreman do
task :dev do
`foreman start -f Procfile.dev`
end
end
desc "Run Foreman using Procfile.dev"
task :foreman => 'foreman:dev'
Run Code Online (Sandbox Code Playgroud)
forman命令在shell中工作正常,但是当我运行时,rake foreman我收到以下错误:
/Users/me/.gem/ruby/2.0.0/gems/bundler-1.5.2/lib/bundler/rubygems_integration.rb:240:in `block in replace_gem': foreman is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/me/.gem/ruby/2.0.0/bin/foreman:22:in `<main>'
Run Code Online (Sandbox Code Playgroud)
福尔曼特别指出:
Ruby users should take care not to install foreman in their project's Gemfile
Run Code Online (Sandbox Code Playgroud)
那么如何才能运行此任务?