Ruby Build a Rails API Namespacing Routes and JSON Checking our API with cURL

problems with simulating and questions about .json necessity

why do we have to specify .json in our request? is it because this tells the app what format of information the request wants? what if we didn't specify it? I can't seem to test this because I'm getting an error that tells me

Dereks-MacBook-Pro:NaomiFreeman_RailsAPI-f1ad3554f3896259b5e2baa9003d8d399b6f1362 DerekJLin$ curl localhost:3000/api/todo_lists
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
  <BODY>
    <H1>Internal Server Error</H1>
    Missing `secret_key_base` for 'development' environment, set this value in `config/secrets.yml`
    <HR>
    <ADDRESS>
     WEBrick/1.3.1 (Ruby/2.3.3/2016-11-21) at
     localhost:3000
    </ADDRESS>
  </BODY>
</HTML>
Dereks-MacBook-Pro:NaomiFreeman_RailsAPI-f1ad3554f3896259b5e2baa9003d8d399b6f1362 DerekJLin$ curl http://localhost:3000/api/todo_lists
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
  <BODY>
    <H1>Internal Server Error</H1>
    Missing `secret_key_base` for 'development' environment, set this value in `config/secrets.yml`
    <HR>
    <ADDRESS>
     WEBrick/1.3.1 (Ruby/2.3.3/2016-11-21) at
     localhost:3000
    </ADDRESS>
  </BODY>
</HTML>
Dereks-MacBook-Pro:NaomiFreeman_RailsAPI-f1ad3554f3896259b5e2baa9003d8d399b6f1362 DerekJLin$ curl http://localhost:3000/api/todo_lists.json
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
  <BODY>
    <H1>Internal Server Error</H1>
    Missing `secret_key_base` for 'development' environment, set this value in `config/secrets.yml`
    <HR>
    <ADDRESS>
     WEBrick/1.3.1 (Ruby/2.3.3/2016-11-21) at
     localhost:3000
    </ADDRESS>
  </BODY>
</HTML>

1 Answer

Zachary Betz
Zachary Betz
10,399 Points

Hi Derek, judging from the error message (pasted below) in the code you posted, it looks like you need to add a key to your config/secrets.yml file.

Missing `secret_key_base` for 'development' environment, set this value in `config/secrets.yml`

To do this, follow the steps under "Setting up a Rails Application" in the Treehouse VM Installation Guide for Mac. http://treehouse.github.io/installation-guides/mac/treehouse-vm-mac.html