From 7d738b7abf206a323a4972b8f2704f1b8d9be480 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 19 Sep 2015 16:48:24 +0800 Subject: [PATCH] fix map/mapping associations that I broke --- app/controllers/application_controller.rb | 2 +- app/models/map.rb | 6 ++++-- app/models/mapping.rb | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 511ab723..0a3d12ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,7 +37,7 @@ private end def require_admin - unless authenticated? && user.admin + unless authenticated? && admin? redirect_to root_url, notice: "You need to be an admin for that." return false end diff --git a/app/models/map.rb b/app/models/map.rb index dffb9fae..ee949676 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -2,8 +2,10 @@ class Map < ActiveRecord::Base belongs_to :user - has_many :topics, -> { Mapping.topicmapping }, :through => :topicmappings - has_many :synapses, -> { Mapping.synapsemapping }, :through => :synapsemappings + has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping + has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping + has_many :topics, through: :topicmappings + has_many :synapses, through: :synapsemappings # This method associates the attribute ":image" with a file attachment has_attached_file :screenshot, :styles => { diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 9d6b4947..a8613840 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,7 +1,7 @@ class Mapping < ActiveRecord::Base - scope :topicmapping, -> { where (category: :Topic) } - scope :synapsemapping, -> { where (category: :Synapse) } + scope :topicmapping, -> { where(category: :Topic) } + scope :synapsemapping, -> { where(category: :Synapse) } belongs_to :topic, :class_name => "Topic", :foreign_key => "topic_id" belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id"