Reputation: 889
I am using ancestry gem in rails 6 on my Location model. On the model, I have a location_type enum.
class Location < ApplicationRecord
enum location_type: ["continent", "country", "state", "state_capital", "country_and_state_capital", "city" ]
when a record has a location type of country I would like to find its "country_and_state_capital" as its country_capital in the location model
def country_capital
self.descendants.where(location_type: "country_and_state_capital")
end
and then call its data in the view
currently when I do this it just shows location
Location Load (0.3ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
↳ app/views/locations/show.html.erb:25
any idea what I can do to just access the one record
Upvotes: 1
Views: 29