Skip to content

Commit

Permalink
feat: Adding format to publication links
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Oct 9, 2024
1 parent 8742a56 commit 8762c22
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/tpi/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TPI
class HomeController < TPIController
def index
@case_studies = CaseStudy.all
@sector_clusters = TPISectorCluster.all.group_by(&:slug).transform_values(&:first)
@sector_clusters = TPISectorCluster.includes(:sectors).group_by(&:slug).transform_values(&:first)

page = TPIPage.find_by(slug: 'homepage-content')
@home_content = {
Expand All @@ -29,7 +29,7 @@ def index
}
@latest_researches = Publication
.published
.includes([:image_attachment, :author_image_attachment])
.includes([image_attachment: :blob, author_image_attachment: :blob, file_attachment: :blob])
.order(publication_date: :desc)
.take(3)

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/file_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ def preview_file_tag(file, options = {})

link_to "Uploaded file: #{file.blob.filename}", rails_blob_path(file), options.merge(target: '_blank')
end

def format_of(file)
Mime::Type.lookup(file.content_type).symbol
end
end
2 changes: 1 addition & 1 deletion app/models/bank_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
class BankAssessment < ApplicationRecord
belongs_to :bank
has_many :results, class_name: 'BankAssessmentResult'
has_many :results, class_name: 'BankAssessmentResult', dependent: :destroy

validates_presence_of :assessment_date
validates :assessment_date, date_after: Date.new(2010, 12, 31)
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<div class="slider" data-tpi-home-slider-target="items">
<% @latest_researches.each_with_index do |research, index| %>
<div>
<%= link_to tpi_publication_download_file_path(slug: research.slug), target: '_blank', class: 'research-box' do %>
<%= link_to tpi_publication_download_file_path(slug: research.slug, format: format_of(research.file)), target: '_blank', class: 'research-box' do %>
<img src="<%= url_for(research.image) %>" />
<div class="research-box__title">
<% if research.author_image.present? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/publications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% if publication.summary.present? %>
<%= link_to publication.title, tpi_publication_path(id: publication.slug), class: 'link is-strong' %>
<% else %>
<%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug), target: '_blank', class: 'link is-strong' %>
<%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug, format: format_of(publication.file)), target: '_blank', class: 'link is-strong' %>
<% end %>
<% else %>
<%= link_to publication.title, show_news_article_tpi_publication_path(id: publication.id), class: "link is-strong" %>
Expand Down

0 comments on commit 8762c22

Please sign in to comment.