Allow to display images on carousel partial.

This commit is contained in:
taitus
2017-07-22 15:39:47 +02:00
parent f8c6422b30
commit fd8e2c1503
3 changed files with 27 additions and 3 deletions

View File

@@ -21,4 +21,13 @@ module WelcomeHelper
end
end
def render_image(recommended, image_field, image_version, image_default)
image_path = if image_field.present? && image_version.present?
recommended.send("#{image_field}", image_version)
elsif image_default.present?
image_default
end
image_tag(image_path) if image_path.present?
end
end

View File

@@ -9,6 +9,7 @@
<% recommendeds.each_with_index do |recommended, index| %>
<li class="orbit-slide <%= active_class(index) %>" data-slide="<%= index %>" style="position: relative; <%= slide_display(index) %>" aria-live="polite">
<div class="card">
<%= render_image(recommended, image_field, image_version, image_default) %>
<div class="card-section">
<%= link_to recommended_path(recommended) do %>
<h5 class="truncate-horizontal-text"><%= recommended.title %></h5>

View File

@@ -3,9 +3,23 @@
<h2 class="text-center"><%= t("welcome.recommended.title") %></h2>
<%= render "recommended_carousel", recommendeds: recommended_debates, key: "debates" %>
<%= render "recommended_carousel", recommendeds: recommended_proposals, key: "proposals" %>
<%= render "recommended_carousel", recommendeds: recommended_budget_investments, key: "budget-investments" %>
<%= render "recommended_carousel", recommendeds: recommended_debates,
key: "debates",
image_field: nil,
image_version: nil,
image_default: "https://dummyimage.com/600x400/000/fff" %>
<%= render "recommended_carousel", recommendeds: recommended_proposals,
key: "proposals",
image_field: nil,
image_version: nil,
image_default: "https://dummyimage.com/600x400/000/fff" %>
<%= render "recommended_carousel", recommendeds: recommended_budget_investments,
key: "budget-investments",
image_field: nil, #example value :image (PR#1691)
image_version: nil, #example value :thumb (PR#1691)
image_default: "https://dummyimage.com/600x400/000/fff" %>
</div>
</div>