Pergunta

I have a Parent (teams) and Child(players) resources nested. I would like to show the child(players) listed when I load team#show I can't find how to set my partial (or direct integration) to load the players inside the team view.

Routes :

resources :teams do 
  resources :players 
end

To load the players of a team XX in the player#index, I use

team_players_path(@team) 

Since I use Devise for user sessions, my team#show controller is

def show
  @team = current_crafter.teams.find(params[:id])
end

But I do not know how to set my team#show controller to get the players, or how to call my partial to pass the card id (in the url)

I'm sure it's a noob thing. Thank you very much in advance for your help

Foi útil?

Solução

To get the players in you team#show, assuming you are using convention where team has_many players.

def show
   @team = current_crafter.teams.find(params[:id])
   @players = @team.players
end

To use a player partial define views/players/_player.html.erb

and to call it, in your team show view use:

<%= render @players %>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top