guys. I have two simple models:
class Restaurant < ApplicationRecord
has_many :reviews
end
and
class Review < ApplicationRecord
belongs_to :restaurant
end
Task is to show all reviews after restaurant or restaurants found
Something like that
class ReviewsController < ApplicationController
def index
@search = Restaurant.search(params[:q])
@reviews = @search.result.reviews
end
end
But this code does not know reviews message cause it`s not an AR::Relation
A very bad solution looks like
def index
@search = Restaurant.ransack(params[:q])
@reviews = @search.result.each_with_object([]) do |rest, arr|
arr << rest.reviews
end
end
But views are very awful. Is there a simple way to get reviews? Thanks