私はホテルのアプリケーションを構築していますが、私はすべてのホテルを最も安い価格で並べ替えることを望みますが、私は目標を達成できないようです。並べ替えには多くの関連があります
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
私はHotel.find(params[:id]).roomtypes.last.price
私はルームタイプのソーティングについて話していません –
私は**ホテルは格安部屋タイプで並べ替えたいです** –
です。それぞれの "ホテル"には様々な価格の**タイプの客室タイプが多数ありますが、ホテルは**最も低いルームタイプの価格で並べ替えるようにします** –