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


Build a simple rails application > profile_name uniqueness

Hi, i'm stuck on this video everything was going along with the video until i add the line uniqueness: true to the end of the line validates :profile_name, presence: true in the file user.rb

I have checked over my code several times and seen all the forums on here related to this issue but can't find a solution anywhere. Code and errors are below:

user.rb class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
                :first_name, :last_name, :profile_name
# attr_accessible :title, :body

validates :first_name, presence: true
validates :last_name, presence: true
validates :profile_name, presence: true, uniqueness: true 
has_many :statuses
def full_name
first_name + " " + last_name

users.yml ellis: first_name: "Ellis" last_name: "Fisher" email: "ellissbsp@gmail.com" profile_name: "ellisfisher" password: "password" password_confirmation: "password"

user_test.rb require 'test_helper'

class UserTest < ActiveSupport::TestCase
test "a user should enter a first name" do
    user = User.new
    assert !user.save
    assert !user.errors[:first_name].empty?

test "a user should enter a last name" do
    user = User.new
    assert !user.save
    assert !user.errors[:last_name].empty?

test "a user should enter a profile name" do
    user = User.new
    assert !user.save
    assert !user.errors[:profile_name].empty?

test "a user should have a unique profile name" do
    user = User.new
    user.profile_name = 'ellisfisher'
    user.email = "ellissbsp@gmail.com"
    user.first_name = "Ellis"
    user.last_name = "Fisher"
    user.password = "password"
    user.password_confirmation = "password"

    assert !user.save
    assert !user.errors[:profile_name].empty?

errors below: test_a_user_should_enter_a_first_name(UserTest): ActiveRecord::StatementInvalid:SQLite3::SQLException: table users has no column named "password_confirmation"

that is error 1 of 4 but they all go along the same line. Was unable to copy from console in Cloud9

Hope there is enough information.

Thanks in advance

Tried the markdown but some of the code just won't set right.

1 Answer

Sorted it appears it was a devise version issue i think as i changed the password fields to encrypted_password and it works. Is this correct Jason Seifer

There appears to be an error in the video at around the 2 minute mark you run a test and it passes. But prior to that in the users.yml file you had the fields password and password_confirmation but after test ran you did not i assume you stopped recording. But this was not made clear at all and caused me a few hours delay in spotting this.