これが機能しない理由がわかりません:
home_team = Team.find_by_name! home_team["name"]
away_team = Team.find_by_name! away_team["name"]
fixture.home_team = home_team
fixture.away_team = away_team
しかし、これは:
home_team = Team.find_by_name! home_team["name"]
away_team = Team.find_by_name! away_team["name"]
fixture.home_team_id = home_team.id
fixture.away_team_id = away_team.id
器具モデル:
class Fixture < ActiveRecord::Base
has_one :home_team, foreign_key: 'home_team_id', class_name: 'Team'
has_one :away_team, foreign_key: 'away_team_id', class_name: 'Team'
...
end
エラーは発生せず、行は保存されますがhome_team_id
、away_team_id
両方null
...
誰か説明できますか?