Hello, I’m in troubles with nested routes. I have three models: Team,
Tournament and TeamTournaments
class Team < ActiveRecord::Base
has_many :tournaments, :through => :team_tournaments
has_many :team_tournaments
class TeamTournament < ActiveRecord::Base
belongs_to :team, :foreign_key => ‘team_id’
belongs_to :tournament, :class_name => ‘League’, :foreign_key =>
‘tournament_id’
class Tournament < ActiveRecord::Base
has_many :teams, :through => :team_tournaments
has_many :team_tournaments
So it’s a N-M relationship between Team and Tournament through
TeamTournaments.
Well, I want to have nested routes from Team to Tournament:
teams/1/tournaments/1
so I’ve mapped it in routes.rb:
I’ve tried these two forms:
map.resources :teams, :has_many => [:tournaments]
map.resources :teams do |team|
team.resources :tournaments
end
And I can do http://localhost:3000/teams/1/tournaments/1, but I can’t
use tournament_url(:team_id => @team, :id => @team.leagues[0]) in a
view because I get the error tournament_url is not defined.
What’s wrong?