我正在建設一個酒店的應用程序,我想通過它的最便宜的房間的價格排序所有酒店,但我似乎無法實現我的目標。排序有很多協會
Roomtype型號>>
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
我不是在談論房型排序 –
我想**'酒店被排序的最便宜的房間類型'** –
這就是;每個「酒店」有不同的價格**的**房型,但我想要酒店按**最低房型價格** –