rake task with multiple parameters - I got stuck
Asked Answered
I

1

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[[email protected],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!

Ignite answered 5/2, 2013 at 17:46 Comment(3)
That error message suggests it can't find the task itself. Do you see it if you do rake -T?Medeah
That suggests that it isn't being loaded rather than an error in the task itself.Medeah
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.Ignite
L
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\[[email protected],password\]

instead.

Lockard answered 11/4, 2013 at 9:45 Comment(1)
If the problem is related to zsh, you can also use rake 'create_user[[email protected],password]' or noglob rake create_user[[email protected],password]. If you're using Robbie Russell's oh-my-zsh, activate the rake plugin to automatically add noglob for you.Lockard

© 2022 - 2024 — McMap. All rights reserved.