我正在建设一个酒店的应用程序,我想通过它的最便宜的房间的价格排序所有酒店,但我似乎无法实现我的目标。排序有很多协会
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
我不是在谈论房型排序 –
我想**'酒店被排序的最便宜的房间类型'** –
这就是;每个“酒店”有不同的价格**的**房型,但我想要酒店按**最低房型价格** –