app/controllers/spree/admin/images_controller.rb in spree_backend-4.2.7 vs app/controllers/spree/admin/images_controller.rb in spree_backend-4.3.0.rc1
- old
+ new
@@ -1,50 +1,36 @@
module Spree
module Admin
class ImagesController < ResourceController
+ include Spree::Admin::ProductConcern
+
+ belongs_to 'spree/product', find_by: :slug
+
before_action :load_edit_data, except: :index
- before_action :load_index_data, only: :index
create.before :set_viewable
update.before :set_viewable
private
def location_after_destroy
- admin_product_images_url(@product)
+ spree.admin_product_images_url(@arent)
end
def location_after_save
- admin_product_images_url(@product)
+ spree.admin_product_images_url(parent)
end
- def load_index_data
- @product = Product.friendly.preload(*variant_index_includes).find(params[:product_id])
- end
-
def load_edit_data
- @product = Product.friendly.preload(*variant_edit_includes).find(params[:product_id])
- @variants = @product.variants.map do |variant|
+ @variants = parent.variants.map do |variant|
[variant.sku_and_options_text, variant.id]
end
- @variants.insert(0, [Spree.t(:all), @product.master_id])
+ @variants.insert(0, [Spree.t(:all), parent.master.id])
end
def set_viewable
@image.viewable_type = 'Spree::Variant'
@image.viewable_id = params[:image][:viewable_id]
- end
-
- def variant_index_includes
- [
- variant_images: [viewable: { option_values: :option_type }]
- ]
- end
-
- def variant_edit_includes
- [
- variants_including_master: { option_values: :option_type, images: :viewable }
- ]
end
end
end
end