From 837e4bde1b9aba76a244f101483d6c730bb987ab Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 20 Apr 2016 08:51:38 +0800 Subject: [PATCH] fix map forking (fix #540) --- app/controllers/maps_controller.rb | 51 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 82b87ffb..91eb97e1 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -158,35 +158,34 @@ class MapsController < ApplicationController @map.arranged = false if params[:topicsToMap] - @all = params[:topicsToMap] - @all = @all.split(',') - @all.each do |topic| - topic = topic.split('/') - mapping = Mapping.new() - mapping.user = @user - mapping.mappable = Topic.find(topic[0]) - mapping.xloc = topic[1] - mapping.yloc = topic[2] - @map.topicmappings << mapping - authorize mapping, :create - mapping.save - end + @all = params[:topicsToMap] + @all = @all.split(',') + @all.each do |topic| + topic = topic.split('/') + mapping = Mapping.new + mapping.map = @map + mapping.user = @user + mapping.mappable = Topic.find(topic[0]) + mapping.xloc = topic[1] + mapping.yloc = topic[2] + authorize mapping, :create? + mapping.save + end - if params[:synapsesToMap] - @synAll = params[:synapsesToMap] - @synAll = @synAll.split(',') - @synAll.each do |synapse_id| - mapping = Mapping.new() - mapping.user = @user - mapping.map = @map - mapping.mappable = Synapse.find(synapse_id) - @map.synapsemappings << mapping - authorize mapping, :create - mapping.save - end + if params[:synapsesToMap] + @synAll = params[:synapsesToMap] + @synAll = @synAll.split(',') + @synAll.each do |synapse_id| + mapping = Mapping.new + mapping.map = @map + mapping.user = @user + mapping.mappable = Synapse.find(synapse_id) + authorize mapping, :create? + mapping.save end + end - @map.arranged = true + @map.arranged = true end authorize @map