2013-02-05 58 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