Skip to content

Commit

Permalink
story/suggestion form: match title length in db
Browse files Browse the repository at this point in the history
This bug has existed since before the site launch, the model and form have never
agreed. The bookmarklet (introduced in 41b6d76) prefills the title field without
awareness of the maximum title length. The model has a limit of 150 (95b4906)
but the form field has a limit of 100 (093747b). Browsers limit text input but
don't prevent form submission and show an error only when the field is focused
(if they show one at all, Safari). The prod db has 379 stories with titles > 100
bytes. Also, SQL databases enforce length as bytes and Rails validates length as
characters, argh. So one more thing that's never been right is
https://web.archive.org/web/20051212105833/http://www.loudthinking.com/arc/000516.html
  • Loading branch information
pushcx committed Jan 24, 2024
1 parent 86cd94e commit fe0d64b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,12 @@ def fetched_attributes
end
end

def self.title_maximum_length
validators_on(:title)
.sole { |v| v.is_a? ActiveRecord::Validations::LengthValidator }
.options[:maximum]
end

private

def valid_canonical_uri?(url)
Expand Down
2 changes: 1 addition & 1 deletion app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<div class="boxline">
<%= f.label :title, "Title:", :class => "required" %>
<%= f.text_field :title, :maxlength => 100 %>
<%= f.text_field :title, maxlength: Story.title_maximum_length %>
<p class="actions title-reminder">
Please remove extraneous components from titles such as the name of the site, blog, section, and author.
<span class="title-reminder-thanks">
Expand Down

0 comments on commit fe0d64b

Please sign in to comment.