3

调用方法“.create”时,我的项目中的所有模型都出现以下错误:

NoMethodError: undefined method `[]' for nil:NilClass
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/attribute_methods/read.rb:86:in `block in read_attribute'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/attribute_methods/read.rb:84:in `fetch'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/attribute_methods/read.rb:84:in `read_attribute'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/attribute_methods/primary_key.rb:19:in `id'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/transactions.rb:341:in `remember_transaction_record_state'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/transactions.rb:280:in `rollback_active_record_state!'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/activerecord/lib/active_record/transactions.rb:269:in `save'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/gems/protected_attributes-1.0.3/lib/active_record/mass_assignment_security/persistence.rb:46:in `create'
from (irb):1
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/railties/lib/rails/commands/console.rb:90:in `start'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/railties/lib/rails/commands/console.rb:9:in `start'
from /home/pavelkhrulev/.rvm/gems/ruby-2.0.0-p195@spasibo/bundler/gems/rails-b52b0bebd147/railties/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

以前一切正常,但我做了捆绑更新,现在不行了。我的宝石文件:

ruby '2.0.0'
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', git: 'https://github.com/rails/rails.git', branch: '4-0-stable'

# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', git: 'https://github.com/rails/sass-rails.git'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', git: 'git://github.com/rails/coffee-rails.git'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
group :production do
  gem 'therubyracer', platforms: :ruby
end

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more:         https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jquery-turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# Use heroku gem to make all features enabled
gem 'rails_12factor', group: :production

# New Relic perfomance monitor
gem 'newrelic_rpm'

# Application gems
gem "devise", :git => "http://github.com/plataformatec/devise.git"
gem 'protected_attributes'
gem 'russian'
gem 'devise-russian'
gem 'kaminari'

# Admin panel
gem 'activeadmin',         github: 'gregbell/active_admin', branch: 'rails4'
gem 'ransack'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'formtastic',          github: 'justinfrench/formtastic'

我查看了源代码,使用了谷歌搜索,但仍然不知道如何解决这个问题。我将不胜感激。我真的坚持了下来。我需要交付几乎完成的项目。

4

2 回答 2

1

确保您的proteced_attributesgem 已更新到最新版本。这个Rails 问题承认存在兼容性错误。

于 2013-11-12T22:32:52.240 回答
0

在 Gemfile 你能试试吗

gem 'rails', '~> 4.0.0' 

代替

 gem 'rails', git: 'https://github.com/rails/rails.git', branch: '4-0-stable' 

然后bundle install

*编辑:在第一条语句中添加逗号

于 2013-09-19T11:04:09.490 回答