diff --git a/app/controllers/related_contents_controller.rb b/app/controllers/related_contents_controller.rb
index aac64dd99..dd25cf02f 100644
--- a/app/controllers/related_contents_controller.rb
+++ b/app/controllers/related_contents_controller.rb
@@ -12,7 +12,7 @@ class RelatedContentsController < ApplicationController
flash[:error] = t('related_content.error', url: Setting['url'])
end
- redirect_to @relationable
+ redirect_to @relationable.url
end
def score_positive
@@ -44,8 +44,9 @@ class RelatedContentsController < ApplicationController
if valid_url?
url = params[:url]
- related_klass = url.match(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)[0].delete("/")
- related_id = url.match(/\/[0-9]+/)[0].delete("/")
+ related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)
+ .flatten.map { |i| i.to_s.singularize.camelize }.join("::")
+ related_id = url.match(/\/(\d+)(?!.*\/\d)/)[1]
@related = related_klass.singularize.camelize.constantize.find_by(id: related_id)
end
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index 579a39525..0953661e4 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -1,6 +1,7 @@
class Budget
class Investment < ActiveRecord::Base
require 'csv'
+ include Rails.application.routes.url_helpers
include Measurable
include Sanitizable
include Taggable
@@ -79,6 +80,10 @@ class Budget
before_validation :set_responsible_name
before_validation :set_denormalized_ids
+ def url
+ budget_investment_path(budget, self)
+ end
+
def self.filter_params(params)
params.select{|x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
end
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 188ab2f93..ec58b2e23 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -1,5 +1,6 @@
require 'numeric'
class Debate < ActiveRecord::Base
+ include Rails.application.routes.url_helpers
include Flaggable
include Taggable
include Conflictable
@@ -49,6 +50,10 @@ class Debate < ActiveRecord::Base
attr_accessor :link_required
+ def url
+ debate_path(self)
+ end
+
def self.recommendations(user)
tagged_with(user.interests, any: true)
.where("author_id != ?", user.id)
diff --git a/app/models/proposal.rb b/app/models/proposal.rb
index 6623e507e..4393d0d51 100644
--- a/app/models/proposal.rb
+++ b/app/models/proposal.rb
@@ -1,4 +1,5 @@
class Proposal < ActiveRecord::Base
+ include Rails.application.routes.url_helpers
include Flaggable
include Taggable
include Conflictable
@@ -71,6 +72,10 @@ class Proposal < ActiveRecord::Base
scope :public_for_api, -> { all }
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) }
+ def url
+ proposal_path(self)
+ end
+
def self.recommendations(user)
tagged_with(user.interests, any: true)
.where("author_id != ?", user.id)
diff --git a/app/models/related_content.rb b/app/models/related_content.rb
index 1fd1b6b0c..8a4cd949c 100644
--- a/app/models/related_content.rb
+++ b/app/models/related_content.rb
@@ -1,6 +1,6 @@
class RelatedContent < ActiveRecord::Base
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
- RELATIONABLE_MODELS = %w{proposals debates}.freeze
+ RELATIONABLE_MODELS = %w{proposals debates budgets investments}.freeze
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
diff --git a/app/views/relationable/_related_list.html.erb b/app/views/relationable/_related_list.html.erb
index db37de27b..5a89aa25a 100644
--- a/app/views/relationable/_related_list.html.erb
+++ b/app/views/relationable/_related_list.html.erb
@@ -7,10 +7,9 @@
<%= render 'relationable/score', related: related_content %>
<% end %>
-
-
+