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

Jorge Diaz
Jorge Diaz
777 Points

I think there is an error in the relevant code section.

The first letter Z looks capitalized as in: /[a-ZA-Z0-9_-+/

Shouldn't the format be: /[a-zA-Z0-9_-+/

Note that I am using rails 4 and thus I also found that I needed to format my expression using: /\A[a-zA-Z0-9_-]+\z/

Where "\A" and "\z" test the start and end of the string.

Without this modification I would fail the test "a user should have a profile name without spaces" on the line: assert !user.errors[:profile_name].empty?

Thank you Jorge. Yes, this was driving me crazy for like an hour. The suggested code makes the test fail. Treehouse needs to fix this.

Your code is correct for the regular expression and makes the test pass!

Thank you!

1 Answer

Juan Ordaz
Juan Ordaz
12,012 Points

newest solution of the problem in the video

class User < ActiveRecord::Base

    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
                :recoverable, :rememberable, :trackable, :validatable

#Associations
    has_many :statuses

#---------------------------------------#

# Validations
    validates :first_name,
                    :last_name,  presence: true

    validates :profile_name,  presence: true,
                                            uniqueness: true,
                                            format: {

                                                            with: /\A[a-zA-Z0-9_-]+\z/,
                                                            message: "Must be formatted correctly."

                                                        }

#---------------------------------------#

    def full_name
        first_name + " " + last_name
    end
end