NoMethodError in LeaguesController#show

undefined method `league_id' for nil:NilClass
Extracted source (around line #8):
6
7
8
9
10
11
              
league = prepare_class('Category').where(country: country).where("slug LIKE ?", "%#{league}%").first
season_id = Season.maximum('id')
matches = prepare_class('Match').where(league_id: league.league_id, season_id: season_id)
prepare(matches)
end

Rails.root: /home/offside/websites/meczeonline

Application Trace | Framework Trace | Full Trace

Request

Parameters:

{"language"=>"na-zywo", "sport"=>"pilka-nozna", "country"=>"dania-superliga", "league"=>"esbjerg-randers-fc"}

Response

Headers:

None