Added improvements to related contents
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
<%= render 'relationable/score', related: related_content %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<span class="related-content-title"><%= t("related_content.content_title.#{related.class.name.downcase}") %></span><br>
|
||||
<span class="related-content-title"><%= t("related_content.content_title.#{related.model_name.singular}") %></span><br>
|
||||
<h3 class="inline-block">
|
||||
<%= link_to related.title, eval("#{related.class.name.downcase}_path(related)") %>
|
||||
<%= link_to related.title, related.url %>
|
||||
</h3>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user