diff --git a/app/controllers/tpi/home_controller.rb b/app/controllers/tpi/home_controller.rb index 67feee9a2..84dd48c51 100644 --- a/app/controllers/tpi/home_controller.rb +++ b/app/controllers/tpi/home_controller.rb @@ -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 = { @@ -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) diff --git a/app/helpers/file_helper.rb b/app/helpers/file_helper.rb index bd985ae8b..ba3cb8d35 100644 --- a/app/helpers/file_helper.rb +++ b/app/helpers/file_helper.rb @@ -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 diff --git a/app/models/bank_assessment.rb b/app/models/bank_assessment.rb index 329f179dd..1aec7d95f 100644 --- a/app/models/bank_assessment.rb +++ b/app/models/bank_assessment.rb @@ -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) diff --git a/app/views/tpi/home/index.html.erb b/app/views/tpi/home/index.html.erb index 493feb070..f9929994f 100644 --- a/app/views/tpi/home/index.html.erb +++ b/app/views/tpi/home/index.html.erb @@ -144,7 +144,7 @@
<% @latest_researches.each_with_index do |research, index| %>
- <%= 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 %>
<% if research.author_image.present? %> diff --git a/app/views/tpi/publications/_list.html.erb b/app/views/tpi/publications/_list.html.erb index f3c5e9c34..df1024b45 100644 --- a/app/views/tpi/publications/_list.html.erb +++ b/app/views/tpi/publications/_list.html.erb @@ -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" %>