Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Building the Profile Page Testing the Profile Name

JJ Reich
JJ Reich
6,180 Points

Having Problem with REGEX on this video

Once I repaired the regex in this video, it passes the "profile should be correctly formatted" test, but now fails the "a user should have a profile name without spaces" test. Best as I can tell, there is something wrong with my regex ( /[a-zA-Z0-9_-}+/ ). In fact, it doesn't matter what I put into my profile_name now, it passes the correct format test in all cases as long as the profile name isn't empty.

My whole validation for profile_name is:

validates :profile_name, presence: true, uniqueness: true, format: { with: /[a-zA-Z0-9_-]+/, message: 'Must be formatted correctly.' }

The failure that comes up is "Failed assertion, no message given." And it is the line that says:

assert !user.errors[:profile_name].empty?
JJ Reich
JJ Reich
6,180 Points

correction: The regex I'm using is /[a-zA-Z0-9_-]+/ The above was a typo - not the actual problem.

1 Answer

The correct regex would be /\A[a-zA-Z0-9_-]+\z/ this is because it needs to find the starting and ending of the captured string and if you use ^ or /s it will fail

JJ Reich
JJ Reich
6,180 Points

Thank you. Worked 4.0!