Control when the investment is trying to relate to itself.

This commit is contained in:
Vicente Mendoza
2018-02-01 14:28:56 +01:00
parent 2a678dfd4a
commit 74124fb784
4 changed files with 11 additions and 3 deletions

View File

@@ -5,13 +5,18 @@ class RelatedContentsController < ApplicationController
def create
if relationable_object && related_object
RelatedContent.create(parent_relationable: @relationable, child_relationable: @related, author: current_user)
flash[:success] = t('related_content.success')
if relationable_object.url != related_object.url
RelatedContent.create(parent_relationable: @relationable, child_relationable: @related, author: current_user)
flash[:success] = t('related_content.success')
else
flash[:error] = t('related_content.error_itself')
end
else
flash[:error] = t('related_content.error', url: Setting['url'])
end
redirect_to @relationable.url
end