Я создаю приложение для отелей, и мне хотелось бы отсортировать все отели по цене самого дешевого номера, но, похоже, я не могу достичь своей цели.
Тип номера Модель>>
class Roomtype < ActiveRecord::Base
mount_uploader :image, RimageUploader
belongs_to :hotel
has_many :order_items
default_scope { order(:price => :desc)}
end
Модель отеля>>
class Hotel < ActiveRecord::Base
has_many :roomtypes, -> { order(:price => :desc) }
has_many :hotel_images
belongs_to :destination
belongs_to :area
accepts_nested_attributes_for :hotel_images
def price
price = self.roomtypes.last.price
end
end
Мне нужно default_scope
, чтобы отели сортировались по Hotel.find(params[:id]).roomtypes.last.price