From 86926da612eaff594c9c84a6cecd3d68417be72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sun, 21 Jul 2024 15:35:43 +0800 Subject: [PATCH] Fix bug. --- app/controllers/archives_controller.rb | 3 +-- app/models/archive_file_multiple.rb | 4 ++-- app/views/admin/archive_files/_form_file.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index c4dc4cb..4d7428c 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -217,8 +217,7 @@ class ArchivesController < ApplicationController file_id = params[:file] file = ArchiveFileMultiple.find(file_id) rescue nil if !file.nil? && file.file.present? - file.download_count = file.download_count + 1 - file.save + file.inc(download_count: 1) @url = file.file.url begin @path = file.file.file.file rescue "" diff --git a/app/models/archive_file_multiple.rb b/app/models/archive_file_multiple.rb index 6310b4e..b6904d4 100644 --- a/app/models/archive_file_multiple.rb +++ b/app/models/archive_file_multiple.rb @@ -8,7 +8,7 @@ class ArchiveFileMultiple field :file_title, localize: true # field :description field :download_count, type: Integer, default: 0 - field :choose_lang, :type => Array, :default => ["en","zh_tw"] + field :choose_lang, :type => Array, :default => I18n.available_locales.map{|l| l.to_s} field :should_destroy, :type => Boolean field :sort_number, :type => Integer @@ -19,7 +19,7 @@ class ArchiveFileMultiple self.choose_lang.include?(lang) end - belongs_to :archive_file + belongs_to :archive_file, index: true # has_many :archive_file_multiple_langs, :autosave => true, :dependent => :destroy diff --git a/app/views/admin/archive_files/_form_file.html.erb b/app/views/admin/archive_files/_form_file.html.erb index 62690a8..205fe42 100644 --- a/app/views/admin/archive_files/_form_file.html.erb +++ b/app/views/admin/archive_files/_form_file.html.erb @@ -37,13 +37,13 @@ <% @site_in_use_locales.each do |locale| %>
  • <% end %> - <%= hidden_field_tag "archive_file[archive_file_multiples_attributes][#{( form_file.new_record? ? 'new_archive_file_multiples' : "#{i}" )}][choose_lang][]", '' %> + <%= hidden_field_tag "#{f.object_name}[choose_lang][]", '' %> <% if form_file.new_record? %>