2013-02-05 50 views
0

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

输出:

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

我真的卡住了。我发现的所有建议,即使在这里,在StackOverflow中,都没有涵盖两个参数的情况,或者已经过时/不工作。请帮忙!

+2

该错误消息表明它无法找到任务本身。如果你做'rake -T',你会看到吗? – Shadwell

+1

这表明它没有被加载,而不是任务本身的错误。 – Shadwell

+1

这是Ruby的品牌疾病:它从不给出确切的错误信息来帮助弄清楚发生了什么。在这个特定的情况下,是否会说'rake找不到名为'create_user''的任务,我很久以前就已经解决了这个问题。 – Paul

回答

0

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

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

尝试使用:

rake create_user\[[email protected],password\] 

代替。

+0

如果问题与zsh有关,您也可以使用'rake'create_user [user @ host.com,password]'或'noglob rake create_user [user @ host.com,password]'。如果您使用的是Robbie Russell的[oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh),请激活[rake插件](https://github.com/robbyrussell/oh -my-zsh/blob/master/plugins/rake/rake.plugin.zsh)为你自动添加'noglob'。 –

+0

正确的答案是对问题的评论。 – Paul