For customer_favs I was able to save all the instances of a favorite for the current customer I am working with. The favorite for a customer consists of the customer id and restaurant id. With that I decided to iterate through it and also iterate through all of the restaurants and see if the id of that the restaurant instance is the same as the restaurant_id of the favorite and return it which gives me an array of favorites.
Now what I am trying to do is find a way to return the instance of the restaurant through the favorite which contains the restaurant_id, I just want to get the restaurant's name. I decided to iterate again though the array of favorites and iterate through the restaurants and compare to see if the restaurant_id of the favorites is the same as the one of the instances of the restaurant and have those instances saved inside of the variable but I am getting an error saying " undefined method `restaurant_id' ".
def view_all_favorites(customer)
customer_favs = customer.favorites
get_res_id = customer_favs.each do |fav_res|
Restaurant.all.select do |res|
res.id == fav_res.restaurant_id
end
end
get_res = Restaurant.all.select do |res|
get_res_id.restaurant_id == res.id
end
puts "#{get_res}"
end