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'])
|
flash[:error] = t('related_content.error', url: Setting['url'])
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to @relationable
|
redirect_to @relationable.url
|
||||||
end
|
end
|
||||||
|
|
||||||
def score_positive
|
def score_positive
|
||||||
@@ -44,8 +44,9 @@ class RelatedContentsController < ApplicationController
|
|||||||
if valid_url?
|
if valid_url?
|
||||||
url = params[:url]
|
url = params[:url]
|
||||||
|
|
||||||
related_klass = url.match(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)[0].delete("/")
|
related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)
|
||||||
related_id = url.match(/\/[0-9]+/)[0].delete("/")
|
.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)
|
@related = related_klass.singularize.camelize.constantize.find_by(id: related_id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class Budget
|
class Budget
|
||||||
class Investment < ActiveRecord::Base
|
class Investment < ActiveRecord::Base
|
||||||
require 'csv'
|
require 'csv'
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
include Measurable
|
include Measurable
|
||||||
include Sanitizable
|
include Sanitizable
|
||||||
include Taggable
|
include Taggable
|
||||||
@@ -79,6 +80,10 @@ class Budget
|
|||||||
before_validation :set_responsible_name
|
before_validation :set_responsible_name
|
||||||
before_validation :set_denormalized_ids
|
before_validation :set_denormalized_ids
|
||||||
|
|
||||||
|
def url
|
||||||
|
budget_investment_path(budget, self)
|
||||||
|
end
|
||||||
|
|
||||||
def self.filter_params(params)
|
def self.filter_params(params)
|
||||||
params.select{|x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
|
params.select{|x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require 'numeric'
|
require 'numeric'
|
||||||
class Debate < ActiveRecord::Base
|
class Debate < ActiveRecord::Base
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
include Flaggable
|
include Flaggable
|
||||||
include Taggable
|
include Taggable
|
||||||
include Conflictable
|
include Conflictable
|
||||||
@@ -49,6 +50,10 @@ class Debate < ActiveRecord::Base
|
|||||||
|
|
||||||
attr_accessor :link_required
|
attr_accessor :link_required
|
||||||
|
|
||||||
|
def url
|
||||||
|
debate_path(self)
|
||||||
|
end
|
||||||
|
|
||||||
def self.recommendations(user)
|
def self.recommendations(user)
|
||||||
tagged_with(user.interests, any: true)
|
tagged_with(user.interests, any: true)
|
||||||
.where("author_id != ?", user.id)
|
.where("author_id != ?", user.id)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class Proposal < ActiveRecord::Base
|
class Proposal < ActiveRecord::Base
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
include Flaggable
|
include Flaggable
|
||||||
include Taggable
|
include Taggable
|
||||||
include Conflictable
|
include Conflictable
|
||||||
@@ -71,6 +72,10 @@ class Proposal < ActiveRecord::Base
|
|||||||
scope :public_for_api, -> { all }
|
scope :public_for_api, -> { all }
|
||||||
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) }
|
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)
|
def self.recommendations(user)
|
||||||
tagged_with(user.interests, any: true)
|
tagged_with(user.interests, any: true)
|
||||||
.where("author_id != ?", user.id)
|
.where("author_id != ?", user.id)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class RelatedContent < ActiveRecord::Base
|
class RelatedContent < ActiveRecord::Base
|
||||||
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
|
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
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|||||||
@@ -7,10 +7,9 @@
|
|||||||
<%= render 'relationable/score', related: related_content %>
|
<%= render 'relationable/score', related: related_content %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<span class="related-content-title"><%= t("related_content.content_title.#{related.model_name.singular}") %></span><br>
|
||||||
<span class="related-content-title"><%= t("related_content.content_title.#{related.class.name.downcase}") %></span><br>
|
|
||||||
<h3 class="inline-block">
|
<h3 class="inline-block">
|
||||||
<%= link_to related.title, eval("#{related.class.name.downcase}_path(related)") %>
|
<%= link_to related.title, related.url %>
|
||||||
</h3>
|
</h3>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user