2013-10-03 58 views
1

我有这样红宝石不能DUP Fixnum对象

ssh_files = ["id_rsa.pub","id_rsa"] 
ssh_files.each_with_index do |item, index| 
     ssh_files[index] = generate_ssh_path(creator).concat(item) 
     FileUtils.mkdir_p(ssh_files[index], 0770) unless File.exists?(generate_ssh_path(creator)) 

末 一些代码,我得到这个错误信息

TypeError (can't dup Fixnum): 
    command.rb:45:in `block in generate_ssh_key' 
    command.rb:42:in `each' 
    command.rb:42:in `each_with_index' 

这里编辑的堆栈

TypeError (can't dup Fixnum): 
    command.rb:44:in `block in generate_ssh_key' 
    command.rb:42:in `each' 
    command.rb:42:in `each_with_index' 
    command.rb:42:in `generate_ssh_key' 
    key.rb:14:in `create_key' 
    key.rb:10:in `initialize' 
    app/models/user.rb:207:in `new' 
    app/models/user.rb:207:in `ssh_key' 
+1

'ssh_files [file]'应该是'ssh_files [index]'everywherel,'| index,file |'应该是'| file,index |'。 – lurker

+0

@ArupRakshit我改变了像你这样的建议我现在得到这个消息类型错误(字符串隐式转换为整数): command.rb:43:在'[] =” – user1611830

+0

@ user1611830赫姆我知道..命名约定只是显示错误印象......就是这样。但错误的是别的地方.. –

回答

3

选项mkdir_p都应该是一个Hash,因为它接受了多种选择,所以把它称为吨他的方法是:

FileUtils.mkdir_p(ssh_files[index], :mode => 0770) 
+0

就是这样!非常感谢 ! – user1611830

+0

真的是一个很好的调试!我很欣赏:) –

+0

感谢@ArupRakshit:O)有时调试是喜欢玩“在哪里金都”。 – lurker