0
私のアプリをrails 5.0から5.1に移行し、関連モデルにアクセスする際に 'Cant cast Hash'エラーが発生しています。 5.0)。Rails 5.0から5.1 - 1対多の関連付けの 'Cant cast Hash'
sighting.rb:
belongs_to :species, :class_name => 'Species', :foreign_key => 'species_id'
belongs_to :site, :class_name => 'Site', :foreign_key => 'site_id'
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
belongs_to :spotter, :class_name => 'User', :foreign_key => 'spotter_id'
species.rb:
has_many :sightings, :class_name => 'Sighting', :foreign_key => 'species_id', :dependent => :restrict_with_exception
site.rb:コンソールで
has_many :sightings, :class_name => 'Sighting', :foreign_key => 'site_id', :dependent => :restrict_with_exception
は(データベースを播種した):
Sighting.find(1).site
は、正しいサイトモデルを返します。一方
Sighting.find(1).species
エラー
TypeError: can't cast Hash
を返す両方関連モデル(ならびにユーザモデル - 図示せず)は、全て同じ方法で設定されています。そして、レールに戻すと、すべてがうまく動作します。