Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

#1: Initial revision by user avatar Monica Cellio‭ · 2022-09-20T03:01:26Z (about 2 years ago)
How should I fix this incorrect error message (don't quite understand the code)
I saw [this report about a bug in an error message](https://meta.codidact.com/posts/287036) and figured that would be an easy fix.  The incorrect error message is: "Tags can't have more than 5 tags".  That should be "Posts can't have...".  I figured I'd need to find and edit a string.

I grepped the code and found my way to `app/models/post.rb`, which includes this:

```
  def maximum_tags
    if tags_cache.length > 5
      errors.add(:tags, "can't have more than 5 tags")
    elsif tags_cache.empty?
      errors.add(:tags, 'must have at least one tag')
    end
  end
```

What is `:tags` here?  I don't see anything in this file that defines it, so it must be coming from somewhere else.  (Have I mentioned I'm very much a newbie with Ruby and Rails?)

I think the logic here is that the error is being _caused_ by tags validation, so we're adding it to a set of errors about that field.  But we don't want to use the name of the field in the error message here.

I realize it's possible to hack around this problem by changing the string here to a sentence that can legitimately begin with the word "Tags", but I'd rather understand what the correct change would be.