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 Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Adding Validations to Todo Items

Line of code Jason uses causes error

After the step where jason adds the line

length: { minimum: 2 }

to the app/models/todo_item.rb file it gives the error

Adding todo items displays an error with no content (FAILED - 1) is successful with valid content (FAILED - 2) displays an error with content less than 2 characters long (FAILED - 3)

Failures:

1) Adding todo items displays an error with no content Failure/Error: click_link "List Items" SyntaxError: /Users/hsh2692/projects/odot/app/models/todo_item.rb:5: syntax error, unexpected ':', expecting keyword_end length: { minimum: 2 } ^ # ./app/views/todo_items/index.html.erb:5:in _app_views_todo_items_index_html_erb___3584457723259976203_70216854123700' # ./spec/features/todo_items/create_spec.rb:9:inblock in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:8:in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:25:inblock (2 levels) in <top (required)>'

2) Adding todo items is successful with valid content Failure/Error: click_link "List Items" SyntaxError: /Users/hsh2692/projects/odot/app/models/todo_item.rb:5: syntax error, unexpected ':', expecting keyword_end length: { minimum: 2 } ^ # ./app/views/todo_items/index.html.erb:5:in _app_views_todo_items_index_html_erb___3584457723259976203_70216854123700' # ./spec/features/todo_items/create_spec.rb:9:inblock in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:8:in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:14:inblock (2 levels) in <top (required)>'

3) Adding todo items displays an error with content less than 2 characters long Failure/Error: click_link "List Items" SyntaxError: /Users/hsh2692/projects/odot/app/models/todo_item.rb:5: syntax error, unexpected ':', expecting keyword_end length: { minimum: 2 } ^ # ./app/views/todo_items/index.html.erb:5:in _app_views_todo_items_index_html_erb___3584457723259976203_70216854123700' # ./spec/features/todo_items/create_spec.rb:9:inblock in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:8:in visit_todo_list' # ./spec/features/todo_items/create_spec.rb:36:inblock (2 levels) in <top (required)>'

Finished in 0.33155 seconds 3 examples, 3 failures

Failed examples:

rspec ./spec/features/todo_items/create_spec.rb:24 # Adding todo items displays an error with no content rspec ./spec/features/todo_items/create_spec.rb:13 # Adding todo items is successful with valid content rspec ./spec/features/todo_items/create_spec.rb:35 # Adding todo items displays an error with content less than 2 characters long

Randomized with seed 40801

I tried to decipher the error message and assumed that the first ":" needed to be deleted which gave a similar error complaining about the second ":". After deleting both of the ":" I was left with the same error that Jason had before he added the line of code.

1 Answer

Brandon Barrette
Brandon Barrette
20,485 Points

Do you have it like this?

validates :content, presence: true, length: {minimum: 2}

Wow, thanks. I somehow missed the comma after true even after scanning back through the code for about an hour.