0

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!

Paul
  • 25,812
  • 38
  • 124
  • 247
  • 2
    That error message suggests it can't find the task itself. Do you see it if you do `rake -T`? – Shadwell Feb 05 '13 at 17:50
  • 1
    That suggests that it isn't being loaded rather than an error in the task itself. – Shadwell Feb 05 '13 at 17:53
  • 1
    This is the Ruby's brand-disease: it never gives exact error messages to help figure out what happened. Will it in this particular case say something like `rake couldn't find task with name 'create_user'`, I would have fixed this a long time ago. – Paul Feb 05 '13 at 18:48

1 Answers1

0

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.

  • If the problem is related to zsh, you can also use `rake 'create_user[user@host.com,password]'` or `noglob rake create_user[user@host.com,password]`. If you're using Robbie Russell's [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh), activate the [rake plugin](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/rake/rake.plugin.zsh) to automatically add `noglob` for you. – James Wilberforce-Andrews Apr 11 '13 at 11:35