[Mascots] Fix handling of app names with spaces in them

Use comma as a separator instead.
Closes #551
This commit is contained in:
Earlopain 2023-10-15 19:14:21 +02:00
parent 2624a0f706
commit 4a26251e77
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
3 changed files with 4 additions and 4 deletions

View File

@ -322,9 +322,9 @@ class ApplicationRecord < ActiveRecord::Base
# The `<attribute>=` setter parses strings into an array using the
# `parse` regex. The resulting strings can be converted to another type
# with the `cast` option.
def array_attribute(name, parse: /[^[:space:]]+/, cast: :itself)
def array_attribute(name, parse: /[^[:space:]]+/, join_character: " ", cast: :itself)
define_method "#{name}_string" do
send(name).join(" ")
send(name).join(join_character)
end
define_method "#{name}_string=" do |value|

View File

@ -1,7 +1,7 @@
class Mascot < ApplicationRecord
belongs_to_creator
array_attribute :available_on
array_attribute :available_on, parse: /[^,]+/, join_character: ","
attr_accessor :mascot_file
validates :display_name, :background_color, :artist_url, :artist_name, presence: true

View File

@ -5,7 +5,7 @@
<%= f.input :background_color %>
<%= f.input :artist_url %>
<%= f.input :artist_name %>
<%= f.input :available_on_string, label: "Available on" %>
<%= f.input :available_on_string, label: "Available on", hint: "Separated by a comma, don't include spaces before/after" %>
<%= f.input :active %>
<%= f.submit %>
<% end %>