具有多个参数的 rake 任务 - 我被卡住了 [英] rake task with multiple parameters - I got stuck

查看:50
本文介绍了具有多个参数的 rake 任务 - 我被卡住了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rake 任务本身:

desc "This task creates a new user"
task :create_user, [:email, :password] => :environment do |t, args|
  trole = Role.find_by_name('translator')
  User.create(
      :email => args.email,
      :password => args.password,
      :password_confirmation => args.password,
      :role_id => trole.id)
end

电话:

rake create_user[user@host.com,password]

输出:

rake aborted!
Don't know how to build task 'create_user'

我真的卡住了.我在 StackOverflow 上找到的所有建议,甚至在这里,要么没有包含两个参数的情况,要么已经过时/不起作用.请帮忙!

I really got stuck. All the advices I've found, even here, on StackOverflow, either don't cover the situation with two parameters, or are outdated/not working. Please help!

推荐答案

您编写的语法在 bash 中应该可以正常工作,所以我猜您正在使用 zsh?

The syntax you've written should work fine in bash, so I'm guessing you're using zsh?

如果是这样,它就不能正确解析 [],这些需要被转义.

If so, it can't parse the [] correctly and these need to be escaped.

尝试使用:

rake create_user\[user@host.com,password\]

相反.

这篇关于具有多个参数的 rake 任务 - 我被卡住了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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