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 Rails API Coding the API Rails API CSRF Verification

Carlos Carrillo
Carlos Carrillo
1,642 Points

Im following the steps but my code breaks

Althought I follow these steps, it breaks:
curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"title":"The Title will go here"}' http://localhost:3000/api/todo_lists

HTTP/1.1 500 Internal Server Error X-Frame-Options: SAMEORIGIN X-Xss-Protection: 1; mode=block X-Content-Type-Options: nosniff Content-Type: application/json Cache-Control: no-cache X-Request-Id: 4e2eec08-3a6f-4569-8ed2-bf7145226312 X-Runtime: 0.002951 Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) Date: Sat, 23 May 2015 14:49:09 GMT Content-Length: 0 Connection: Keep-Alive Set-Cookie: request_method=POST; path=/

Any idea? Thanks in advance

1 Answer

Make sure that your todo_list passes the validations set in app/models/todo_list.rb I added "description to app/controllers/api/todo_list_controller.rb file in the

params.require("todo_list").permit("title", "description")` line.

I didn't have a description, and my validations require that I have a description.

So my curl command went as such:

curl \ 
-i \ 
-H "Accept: application/json" \
 -H "Content-type: application/json" \ 
-X POST \ 
-d '{"title":"Title goes here", "description":"description goes here"}' \
 http://localhost:3000/api/todo_lists

or written out it goes as such:

curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"title":"title goes here", "description":"description goes here"}' http://localhost:3000/api/todo_lists

Note that after adding "description" to the params line i was able to create one without a description as well.