diff --git a/app/helpers/namings_helper.rb b/app/helpers/namings_helper.rb index dafa4ebf7d..56c5fd0029 100644 --- a/app/helpers/namings_helper.rb +++ b/app/helpers/namings_helper.rb @@ -251,8 +251,7 @@ def your_vote_html(naming, vote) # N+1: should not be checking permission here # N+1: vote is naming.users_vote, so should be an instance of Vote. # NamingsController#index iteration over namings in table_row - # This could be a form with model: vote so it can has an id, sent in url - # rubocop:disable Metrics/MethodLength + # This may be a form_with(model: vote) so it gets an id, sent in url def naming_vote_form(naming, vote, context: "blank") vote_id = vote&.id method = vote_id ? :patch : :post @@ -262,25 +261,13 @@ def naming_vote_form(naming, vote, context: "blank") else Vote.confidence_menu end - localizations = { - lose_changes: :show_namings_lose_changes.l.tr("\n", " "), - saving: :show_namings_saving.l - }.to_json - form_with( - model: vote, - url: naming_vote_form_commit_url(naming, vote), method: method, - id: "naming_vote_form_#{naming.id}", - class: "naming-vote-form d-inline-block float-right float-sm-none", - data: { turbo: true, controller: "naming-vote", naming_id: naming.id, - localization: localizations } - ) do |fv| + form_with(**naming_vote_form_args(naming, vote, method)) do |fv| [ fv.select(:value, menu, {}, { class: "form-control w-100", id: "vote_value_#{naming.id}", data: { naming_vote_target: "select", - localization: localizations, action: "naming-vote#sendVote" } }), hidden_field_tag(:context, context), tag.noscript do @@ -291,10 +278,28 @@ def naming_vote_form(naming, vote, context: "blank") ].safe_join end end - # rubocop:enable Metrics/MethodLength private + def naming_vote_form_args(naming, vote, method) + args = { + url: naming_vote_form_commit_url(naming, vote), method: method, + id: "naming_vote_form_#{naming.id}", + class: "naming-vote-form d-inline-block float-right float-sm-none", + data: { turbo: true, controller: "naming-vote", naming_id: naming.id, + localization: naming_vote_form_localizations } + } + args = args.merge(model: vote) if vote + args + end + + def naming_vote_form_localizations + { + lose_changes: :show_namings_lose_changes.l.tr("\n", " "), + saving: :show_namings_saving.l + }.to_json + end + # form can commit to update or create def naming_vote_form_commit_url(naming, vote) if vote&.id diff --git a/app/models/inat_import.rb b/app/models/inat_import.rb index 96c2267473..f7ecddabe0 100644 --- a/app/models/inat_import.rb +++ b/app/models/inat_import.rb @@ -28,7 +28,8 @@ class InatImport < ApplicationRecord belongs_to :user - serialize :log, type: Array + serialize :log, type: Array, coder: YAML + def add_response_error(error) response_errors << "#{error.class.name}: #{error.message}\n" save diff --git a/app/models/naming.rb b/app/models/naming.rb index e64c5a881e..c15409cd8c 100644 --- a/app/models/naming.rb +++ b/app/models/naming.rb @@ -49,7 +49,7 @@ class Naming < AbstractModel belongs_to :user has_many :votes, dependent: :destroy - serialize :reasons + serialize :reasons, coder: YAML before_save :did_name_change? before_save :enforce_default_reasons diff --git a/app/models/observation.rb b/app/models/observation.rb index 6f2ded5e6e..bcb50a1692 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -990,7 +990,7 @@ def saved_change_to_place? # Notes are exported as shown, except that the intial "Notes:" caption is # omitted, and any markup is stripped from the keys. - serialize :notes + serialize :notes, coder: YAML # value of observation.notes if there are no notes def self.no_notes diff --git a/app/models/user.rb b/app/models/user.rb index 5b3943bfd6..9d65b30fe9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -319,7 +319,7 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength belongs_to :license # user's default license belongs_to :location # primary location - serialize :content_filter, type: Hash + serialize :content_filter, type: Hash, coder: YAML ############################################################################## # @@ -344,8 +344,8 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength # This causes the data structures in these fields to be serialized # automatically with YAML and stored as plain old text strings. - serialize :bonuses - serialize :alert + serialize :bonuses, coder: YAML + serialize :alert, coder: YAML scope :by_contribution, lambda { order(contribution: :desc, name: :asc, login: :asc) diff --git a/app/models/user_stats.rb b/app/models/user_stats.rb index bfcfe310bb..348d0c7ae2 100644 --- a/app/models/user_stats.rb +++ b/app/models/user_stats.rb @@ -73,9 +73,9 @@ class UserStats < ApplicationRecord # This causes the data structures in these fields to be serialized # automatically with YAML and stored as plain old text strings. - serialize :languages, type: Hash - serialize :bonuses - serialize :checklist, type: Hash + serialize :languages, type: Hash, coder: YAML + serialize :bonuses, coder: YAML + serialize :checklist, type: Hash, coder: YAML ALL_FIELDS = { name_description_authors: { weight: 100 }, diff --git a/config/application.rb b/config/application.rb index 410fd0959f..1592e4e4a9 100644 --- a/config/application.rb +++ b/config/application.rb @@ -43,7 +43,7 @@ class Application < Rails::Application # Uncomment this after migrating to all recommended default configs for 7.1 # config/initializers/new_framework_defaults_7_1.rb - # config.load_defaults = 7.1 + # config.load_defaults(7.1) # Set Time.zone default to the specified zone and # make Active Record auto-convert to this zone.