简体   繁体   English

如何在Rails 4中使用2个args和环境运行此rake任务?

[英]how to run this rake task with 2 args and environment in rails 4?

Here are the first few lines of my rake task: 这是我的瑞克任务的前几行:

 desc "Import National Data into DB\n Usage: 
 rake import_regional[/Users/am/0925/xyz.csv, some_market]"

 task :import_regional, [:file_path, :market] => [:environment] do |t, args|

 .......

Here is how Im trying to run this task on the command line: 这是我试图在命令行上运行此任务的方法:

 rake import_regional ["/Users/xyz.csv", "northeast"]

when I try this, I get this error 当我尝试这个时,我得到这个错误

 rake aborted!
 Don't know how to build task 
 'import_regional[/Users/xyz.csv,'

I suspect it's the way in which you're running the task on the command-line; 我怀疑这是您在命令行上运行任务的方式。 the [] doesn't have its Ruby meaning, there. []没有Ruby的含义。 Instead, maybe see if this works for you: 相反,也许看看这是否适合您:

rake "import_regional[/Users/xyz.csv, northeast]"

This should still allow for spaces, etc. in :file_path , if required. 如果需要,这仍应在:file_path留出空格等。

Peace, tiredpixel 和平,疲倦

Command line isn't a Ruby interpreter, it's mangling things before it gets to Rake. 命令行不是Ruby解释器,而是在到达Rake之前对其进行处理。

Try this: 尝试这个:

rake "import_regional['/Users/xyz.csv', 'northeast']"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM