just do it in the controller

This commit is contained in:
Connor Turland 2016-04-22 12:51:07 +00:00
parent 7cf0ddc2ee
commit ce72bde309
2 changed files with 7 additions and 9 deletions

View file

@ -45,6 +45,13 @@ class MappingsController < ApplicationController
@mapping = Mapping.find(params[:id]) @mapping = Mapping.find(params[:id])
authorize @mapping authorize @mapping
mappable = @mapping.mappable
if mappable.defer_to_map
mappable.permission = mappable.defer_to_map.permission
mappable.defer_to_map_id = nil
mappable.save
end
@mapping.destroy @mapping.destroy
head :no_content head :no_content

View file

@ -7,8 +7,6 @@ class Mapping < ActiveRecord::Base
belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true
belongs_to :user belongs_to :user
before_destroy :remove_defer
validates :xloc, presence: true, validates :xloc, presence: true,
unless: Proc.new { |m| m.mappable_type == 'Synapse' } unless: Proc.new { |m| m.mappable_type == 'Synapse' }
validates :yloc, presence: true, validates :yloc, presence: true,
@ -28,11 +26,4 @@ class Mapping < ActiveRecord::Base
super(:methods =>[:user_name, :user_image]) super(:methods =>[:user_name, :user_image])
end end
private
def remove_defer(mapping)
mappable = mapping.mappable
mappable.defer_to_map_id = nil
mappable.save
end
end end