app/controllers/admin/variants_controller.rb in spree-0.5.1 vs app/controllers/admin/variants_controller.rb in spree-0.6.0
- old
+ new
@@ -1,10 +1,9 @@
class Admin::VariantsController < Admin::BaseController
resource_controller
belongs_to :product
- before_filter :load_data, :only => [:index, :edit, :new]
-
+
new_action.response do |wants|
wants.html {render :action => :new, :layout => false}
end
create.before do
@@ -21,12 +20,31 @@
# redirect to index (instead of r_c default of show view)
update.response do |wants|
wants.html {redirect_to collection_url}
end
- private
- def load_data
- # this allows extensions to provide their own additional columns in the index and edit views
- @additional_fields = Variant.column_names - ["id", "price", "sku", "product_id"]
+ # override the destory method to set deleted_at value
+ # instead of actually deleting the product.
+ def destroy
+ @variant = Variant.find(params[:id])
+
+ @variant.deleted_at = Time.now()
+ if @variant.save
+ flash[:notice] = "Variant has been deleted"
+ else
+ flash[:notice] = "Variant could not be deleted"
+ end
+
+ redirect_to admin_product_variants_url(params[:product_id])
end
+ private
+ def collection
+ @deleted = (params.key?(:deleted) && params[:deleted] == "on") ? "checked" : ""
+
+ if @deleted.blank?
+ @collection ||= end_of_association_chain.active.find(:all)
+ else
+ @collection ||= end_of_association_chain.deleted.find(:all)
+ end
+ end
end