rake task with multiple parameters - I got stuck

我怕爱的太早我们不能终老 提交于 2019-12-24 19:25:41

问题


The rake task itself:

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

The call:

rake create_user[user@host.com,password]

The output:

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

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!


回答1:


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.

Try using:

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

instead.



来源:https://stackoverflow.com/questions/14713654/rake-task-with-multiple-parameters-i-got-stuck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!