Receiving nil on ID results using select

On my teams table I have a column for ESPN names where ESPN uses it’s
own naming convention for teams. I’m trying to do a simple

@team = “Navy”

@o_team = Team.find_by_espn_team(@team, :select => “ AS
p @o_team[:opponent_id]
p @o_team.opponent_id

In the console it shows the correct number but right after posting the
number it states:

Team = Navy | ESPN ID = 2426 | TEAM ID = 1

NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

61 is the correct ID for the first opponent and both puts show the
correct number. The line this points at points to the first p
@o_team[:opponent_id] and if I remove it and use the second it does the
same, pointing to the second puts statement.

If I try a generic non-select query and use or team_id I receive
a whiny nil error.

Any help would be appreciated.


Team.all(:conditions => {:espn_team => @team}).each do |row|
@o_team =

p @o_team

The .find_by query was the cause. Swapping to all and applying a
condition for the team works.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs