diff --git a/core/app/models/comable/product.rb b/core/app/models/comable/product.rb index f1274351..6d9d3009 100644 --- a/core/app/models/comable/product.rb +++ b/core/app/models/comable/product.rb @@ -7,7 +7,7 @@ class Product < ActiveRecord::Base include Comable::Product::Csvable has_many :variants, class_name: Comable::Variant.name, inverse_of: :product, dependent: :destroy - has_many :images, class_name: Comable::Image.name, dependent: :destroy + has_many :images, -> { order(:id) }, class_name: Comable::Image.name, dependent: :destroy has_and_belongs_to_many :categories, class_name: Comable::Category.name, join_table: :comable_products_categories accepts_nested_attributes_for :variants, allow_destroy: true @@ -24,12 +24,6 @@ class Product < ActiveRecord::Base PREVIEW_SESSION_KEY = :preview_product - # Add conditions for the images association. - # Override method of the images association to support Rails 3.x. - def images - super.order(:id) - end - def image_url image = images.first return image.url if image diff --git a/frontend/app/controllers/comable/home_controller.rb b/frontend/app/controllers/comable/home_controller.rb index d7079ccf..234cf3be 100644 --- a/frontend/app/controllers/comable/home_controller.rb +++ b/frontend/app/controllers/comable/home_controller.rb @@ -8,7 +8,7 @@ def show private def load_products - @products = Comable::Product.limit(5) + @products = Comable::Product.includes(:images, :variants).limit(4) end end end diff --git a/frontend/app/controllers/comable/products_controller.rb b/frontend/app/controllers/comable/products_controller.rb index 5527701d..fa18b8ed 100644 --- a/frontend/app/controllers/comable/products_controller.rb +++ b/frontend/app/controllers/comable/products_controller.rb @@ -3,7 +3,7 @@ class ProductsController < Comable::ApplicationController before_filter :load_category_and_products, only: :index def index - @products = @products.page(params[:page]).per(Comable::Config.products_per_page) + @products = @products.includes(:images, :variants).page(params[:page]).per(Comable::Config.products_per_page) end def show