where
returns an ActiveRecord_Relationship, meaning an object containing CityRace objects for every row in the database with city_race_id2
equals to 3, no matter if there's only one, the result is an ActiveRecord_Relationship
object, and that doesn't respond to name
.
If you need the name of a particular object from that result, you can access to the specific element by its index and invoke name
on it, e.g:
CityRace.where(city_race_id2: "3").first.name
Or to retrieve the name from every object:
CityRace.where(city_race_id2: "3").pluck(:name)
this one returns an array of strings, so, you must iterate over them to print them all or get a specific one.
In the other hand if you need a single row from the query, use find_by
:
CityRace.find_by(city_race_id2: "3").name