저는 루비와 레일이 처음이에요.뒷쪽으로 연결할 수 없습니다.
나는 현재 3 개 모델 (게임, 경기, 선수, 사용자)
game.rb이
has_many :matches
match.rb
belongs_to :game
has_many :players
player.rb
belongs_to :match
belongs_to :user
지금은 토스를 채우고 싶습니다. 전자적 연관성을 보여준다.
기본적으로 내가 무엇을 :
players_controller.rb
def create
@game = Game.find(params[:game_id])
@match = @game.matches.find(params[:match_id])
@player = @match.players.create(params[:player])
@player.user = User.find(current_user.id)
end
을 그 후 내가보기에 전화를 걸
<%= @player.user.email %>
는이 오류가 발생합니다 :
undefined method `email' for nil:NilClass
내 질문에 나는 협회에서 거꾸로 잘못하는거야? 어떻게 든 가능해야합니다
당신은 우리가 당신의 user.rb에 연관성을 보이지는 않지만, 그들은 다음과 같이 추측합니다 :'has_many : players' – Chazu
그것의 사용자 1 : n 플레이어 관계. user.rb'has_many : players' – cschaeffler