Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 错误未定义方法“[]';为零:设计中的零级?_Ruby On Rails_Ruby_Devise_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 错误未定义方法“[]';为零:设计中的零级?

Ruby on rails 错误未定义方法“[]';为零:设计中的零级?,ruby-on-rails,ruby,devise,ruby-on-rails-4,Ruby On Rails,Ruby,Devise,Ruby On Rails 4,我正在从事rails 4的工作 gemfile: C:\Sites\scroll>rake db:migrate == DeviseCreateAuthorizes: migrating ========================================= -- create_table(:authorizes) -> 0.1676s -- add_index(:authorizes, :email, {:unique=>true}) -> 0.

我正在从事rails 4的工作

gemfile:

C:\Sites\scroll>rake db:migrate
==  DeviseCreateAuthorizes: migrating    =========================================
 -- create_table(:authorizes)
 -> 0.1676s
-- add_index(:authorizes, :email, {:unique=>true})
-> 0.0644s
-- add_index(:authorizes, :reset_password_token, {:unique=>true})
-> 0.0418s
==  DeviseCreateAuthorizes: migrated (0.2798s) ================================

rake aborted!
An error has occurred, this and all later migrations canceled:

 undefined method `[]' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
  class DeviseCreateAuthorizes < ActiveRecord::Migration
   def change
    create_table(:authorizes) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :authorizes, :email,                :unique => true
add_index :authorizes, :reset_password_token, :unique => true

 end
end
gem“设计”、“~>3.2.2”

cmd:

C:\Sites\scroll>rake db:migrate
==  DeviseCreateAuthorizes: migrating    =========================================
 -- create_table(:authorizes)
 -> 0.1676s
-- add_index(:authorizes, :email, {:unique=>true})
-> 0.0644s
-- add_index(:authorizes, :reset_password_token, {:unique=>true})
-> 0.0418s
==  DeviseCreateAuthorizes: migrated (0.2798s) ================================

rake aborted!
An error has occurred, this and all later migrations canceled:

 undefined method `[]' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
  class DeviseCreateAuthorizes < ActiveRecord::Migration
   def change
    create_table(:authorizes) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :authorizes, :email,                :unique => true
add_index :authorizes, :reset_password_token, :unique => true

 end
end
>rails g设计:安装

>rails g设计授权

>rake数据库:迁移

错误:

C:\Sites\scroll>rake db:migrate
==  DeviseCreateAuthorizes: migrating    =========================================
 -- create_table(:authorizes)
 -> 0.1676s
-- add_index(:authorizes, :email, {:unique=>true})
-> 0.0644s
-- add_index(:authorizes, :reset_password_token, {:unique=>true})
-> 0.0418s
==  DeviseCreateAuthorizes: migrated (0.2798s) ================================

rake aborted!
An error has occurred, this and all later migrations canceled:

 undefined method `[]' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
  class DeviseCreateAuthorizes < ActiveRecord::Migration
   def change
    create_table(:authorizes) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :authorizes, :email,                :unique => true
add_index :authorizes, :reset_password_token, :unique => true

 end
end
包括--trace

rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `[]' for   nil:NilClassF:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/
2.0.0/gems/activerecord-  4.0.2/lib/active_record/attribute_methods/read.rb:86:in`block in read_attribute'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord- 4.0.2/lib/acti
ve_record/attribute_methods/read.rb:84:in `fetch'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods/read.rb:84:in `read_attribute'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-  4.0.2/lib/active_record/attribute_methods.rb:243:in `block in attributes'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-  4.0.2/lib/active_record/attribute_methods.rb:242:in `each'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods.rb:242:in `each_with_object'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods.rb:242:in `attributes'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods/dirty.rb:84:in`keys_for_partial_write'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods/dirty.rb:78:in `create_record'

`<top (required)>'
F:/RailsInstaller/Ruby2.0.0/bin/rake:23:in `load'
F:/RailsInstaller/Ruby2.0.0/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
rake中止!
发生错误,此迁移和所有后续迁移已取消:
nil:NilClassF:/RailsInstaller/Ruby2.0.0/lib/ruby/gems的未定义方法“[]”/
2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u methods/read.rb:86:在'block in read\u attribute'中
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/acti
ve_record/attribute_methods/read.rb:84:in'fetch'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u methods/read.rb:84:in'read\u attribute'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u方法。rb:243:在“属性中的块”中
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u methods.rb:242:在'each'中
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u方法。rb:242:在“每个对象”中
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u方法。rb:242:在“attributes”中
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u methods/dirty.rb:84:in'keys\u for_partial\u write'
F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active\u record/attribute\u methods/dirty.rb:78:in“create\u record”
`'
F:/RailsInstaller/Ruby2.0.0/bin/rake:23:in'load'
F:/RailsInstaller/Ruby2.0.0/bin/rake:23:in`'
任务:TOP=>db:migrate
迁移:

C:\Sites\scroll>rake db:migrate
==  DeviseCreateAuthorizes: migrating    =========================================
 -- create_table(:authorizes)
 -> 0.1676s
-- add_index(:authorizes, :email, {:unique=>true})
-> 0.0644s
-- add_index(:authorizes, :reset_password_token, {:unique=>true})
-> 0.0418s
==  DeviseCreateAuthorizes: migrated (0.2798s) ================================

rake aborted!
An error has occurred, this and all later migrations canceled:

 undefined method `[]' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
  class DeviseCreateAuthorizes < ActiveRecord::Migration
   def change
    create_table(:authorizes) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :authorizes, :email,                :unique => true
add_index :authorizes, :reset_password_token, :unique => true

 end
end
类designecreates授权false,:default=>
t、 字符串:加密密码,:null=>false,:default=>
##可恢复
t、 字符串:重置密码\u令牌
t、 日期时间:重置密码发送时间
##难忘的
t、 datetime:记住在
##可追踪
t、 整数:计数中的符号,:default=>0,:null=>false
t、 日期时间:当前登录时间
t、 日期时间:上次登录时间
t、 字符串:ip中的当前\u符号\u
t、 字符串:ip中的最后\u签名\u
##可证实
#t.string:确认令牌
#t.datetime:已确认
#t.datetime:确认发送至
#t.string:未确认的电子邮件#仅当使用可再确认
##可锁
#t.integer:failed_尝试,:default=>0,:null=>false#仅当锁定策略为:failed_尝试时
#t.string:unlock_token#仅当解锁策略为:email或:两者皆有时
#t.datetime:locked_在
t、 时间戳
结束
添加索引:authorizes,:email,:unique=>true
添加索引:authorizes,:reset\u password\u token,:unique=>true
结束
结束
出了什么问题


谢谢。

看起来迁移运行得很好。您能否使用
--trace?
运行并将结果添加到您的问题中?我已编辑了do Check,这可能有助于查看迁移的内容。我已将迁移内容包括在内。这一错误已在几篇文章中引用。也许他们是相关的:见:和