Class: Spree::Admin::RelationsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::RelationsController
- Defined in:
- app/controllers/spree/admin/relations_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 8 def create @relation = Relation.new(relation_params) @relation.relatable = @product @relation. = Spree::Variant.find(relation_params[:related_to_id]).product @relation.save respond_with(@relation) end |
#destroy ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 34 def destroy @relation = Relation.find(params[:id]) if @relation.destroy flash[:success] = (@relation, :successfully_removed) respond_with(@relation) do |format| format.html { redirect_to location_after_destroy } format.js { render partial: "spree/admin/shared/destroy" } end else respond_with(@relation) do |format| format.html { redirect_to location_after_destroy } end end end |
#update ⇒ Object
17 18 19 20 21 22 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 17 def update @relation = Relation.find(params[:id]) @relation.update_attribute :discount_amount, relation_params[:discount_amount] || 0 redirect_to((@relation.relatable)) end |
#update_positions ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 24 def update_positions params[:positions].each do |id, index| model_class.where(id: id).update_all(position: index) end respond_to do |format| format.js { render text: 'Ok' } end end |