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

Michael Cola
Michael Cola
9,584 Points

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.