Add method to investments helper to calculate absolute url for investments images. Use it in social share widget.

This commit is contained in:
Senén Rodero Rodríguez
2017-06-24 22:17:27 +02:00
parent 66c1074350
commit cf9a7a21cc
3 changed files with 23 additions and 1 deletions

View File

@@ -1,5 +1,9 @@
module InvestmentsHelper
def investment_image_full_url(investment, version)
URI(request.url) + investment.image.url(version)
end
def investment_image_file_name(investment)
investment.image.url.split('/').last.split("?")[0] if investment.image.present?
end

View File

@@ -1,6 +1,7 @@
<div id="<%= dom_id(investment) %>" class="budget-investment clear">
<div class="panel">
<div class="row">
<div class="small-12 medium-3 large-2 column">
<% if investment.image.exists? %>
<picture>
@@ -16,12 +17,16 @@
<div class="no-image"></div>
<% end %>
</div>
<div class="small-12 medium-6 large-7 column">
<div class="budget-investment-content">
<% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %>
<h3><%= link_to investment.title, namespaced_budget_investment_path(investment) %></h3>
<p class="investment-project-info">
<%= l investment.created_at.to_date %>
<% if investment.author.hidden? || investment.author.erased? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="author">
@@ -39,6 +44,7 @@
</span>
<% end %>
<% end %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= investment.heading.name %>
</p>
@@ -52,6 +58,7 @@
</div>
<% unless investment.unfeasible? %>
<% if investment.should_show_votes? %>
<div id="<%= dom_id(investment) %>_votes"
class="small-12 medium-3 column text-center">
@@ -88,6 +95,7 @@
</p>
</div>
<% end %>
<% end %>
</div>
</div>

View File

@@ -1,4 +1,5 @@
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
<div class="row">
<div class="small-12 medium-9 column">
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>
@@ -18,12 +19,15 @@
<h1><%= investment.title %></h1>
<div class="budget-investment-info">
<%= render '/shared/author_info', resource: investment %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l investment.created_at.to_date %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= investment.heading.name %>
</div>
<br>
<% if investment.image.exists? %>
<div class="row">
<div class="small-12 column text-center">
@@ -39,19 +43,23 @@
</div>
</div>
<% end %>
<p id="investment_code">
<%= t("budgets.investments.show.code_html", code: investment.id) %>
</p>
<% if investment.location.present? %>
<p>
<%= t("budgets.investments.show.location_html", location: investment.location) %>
</p>
<% end %>
<% if investment.organization_name.present? %>
<p>
<%= t("budgets.investments.show.organization_name_html", name: investment.organization_name) %>
</p>
<% end %>
<%= render 'shared/tags', taggable: investment %>
<%= safe_html_with_links investment.description.html_safe %>
@@ -61,10 +69,12 @@
<%= text_with_links investment.external_url %>
</div>
<% end %>
<% if investment.unfeasible? && investment.unfeasibility_explanation.present? %>
<h2><%= t('budgets.investments.show.unfeasibility_explanation') %></h2>
<p><%= investment.unfeasibility_explanation %></p>
<% end %>
<% if investment.should_show_price_info? %>
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
<p><%= investment.price_explanation %></p>
@@ -129,7 +139,7 @@
<%= render partial: 'shared/social_share', locals: {
share_title: t("budgets.investments.show.share"),
title: investment.title,
image_url: investment.image.exists? ? URI(request.url) + investment.image.url(:thumb) : '',
image_url: investment.image.exists? ? investment_image_full_url(investment, :thumb) : '',
url: budget_investment_url(budget_id: investment.budget_id, id: investment.id)
} %>