红宝石不能重复Fixnum

时间:2013-10-03 17:59:04

标签: ruby-on-rails ruby

我有一些像这样的代码

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 个答案:

答案 0 :(得分:3)

mkdir_p的选项应该是Hash,因为它接受各种选项,因此请这样称呼:

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