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'

ソースコードを見て、Google 検索を使用しましたが、これを修正する方法がまだわかりません。どんな助けにも感謝します。私は本当にそれに固執しました。ほぼ完成したプロジェクトを納品する必要があります。

4

2 に答える 2

1

proteced_attributesgem が最新バージョンに更新されていることを確認します。このレールの問題は、互換性のバグがあったことを認めています。

于 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 に答える