问题
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