From 861ab1750aef26c1324fb8a75d269f505534a066 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Mon, 29 Jul 2013 13:38:08 +0200 Subject: [PATCH] Removed the requirement of attachment containers having a project since it is not true for e.g. the Landing Page plugin --- app/controllers/attachments_controller.rb | 7 ++++++- app/models/attachment.rb | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index ceb51b31af..d44b1690f1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -44,7 +44,12 @@ class AttachmentsController < ApplicationController @attachment.container.attachments.delete(@attachment) redirect_to :back rescue ::ActionController::RedirectBackError - redirect_to :controller => '/projects', :action => 'show', :id => @project + # we cannot be sure the container actually has a project (example: LandingPage) + if @project + redirect_to :controller => '/projects', :action => 'show', :id => @project + else + redirect_to home_url + end end private diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 1e6c603d14..91eea8f9b3 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -144,7 +144,8 @@ class Attachment < ActiveRecord::Base end def project - container.project + #not every container has a project (example: LandingPage) + container.respond_to?(:project)? container.project : nil end def visible?(user=User.current)