Skip to content
Kalman Hazins edited this page Feb 26, 2016 · 45 revisions

FAQs - Module 3

Recipe Hunter

HTTParty


Recipe Hunter

Q: API Key: None?

A: You have to create an account and sign in using that account. If you sign in with Facebook, your API Key will be None (which is kinda useless).

Q: How to set an environment variable?

A: It depends on your OS. If you want to set a permanent environment variable:

For Windows 10:

  • Click on the Windows key and type env; select "Edit the system environment variables"
  • Click "Environment variables..."; select "New..." under System variables
  • On Variable Name, enter the name of the variable (in this case, FOOD2FORK_KEY)
  • On Variable Value, enter the value of your API key

For Linux and OSX:

echo 'export FOOD2FORK_KEY = "Your API Key"' >> ~/.profile

NOTE: there is no need to set the ENV['FOOD2FORK_SERVER_AND_PORT'], because this variable will be used only by the grader


Q: My app works, but the tests say the environment variables are not set

A: According to the assignment instructions, the rspec command can be run from any location. However, the tests are looking for the strings "FOOF2FORK_KEY" and "FOOD2FORK_SERVER_AND_PORT" within ./app (relative path to app directory). That's why the tests have to be run from the root of your application (the folder that contains the app directory). Because of this, please copy the spec folder and .rspec file to be alongside the app directory prior to running the rspec command.


Q: My app works on the browser, but does not pass the tests

A: Take a look at the error messages you get when you run rspec. If you see something like the following:

Failures:
1) Recipes App displays 'Kahlúa-Spiked' when request parameter 'search' is mocha
(...) # left out to make it more readable

Request to 'http://localhost:3000?search=mocha' failed to reach server, check DNS and/or server status

The message you are seeing is basically saying that your server is not running.

Make sure you leave your server running in one window (rails server) and run the RSpec tests from another terminal window.


Q: I can see "Kahúla-Spiked" on the page, but the test does not pass

A: If you start Rails server, search for "mocha" and see "Kahúla-Spiked" on the page, but the test does not pass, you need to check the URL for the search page. It has to be http://localhost:3000/?search=mocha. The URL tells you two things:

  1. The RecipesController index action must be the root of the application
  2. The parameter name has to be search (not looking_for)

Q: How to deploy 'Recipe Finder' to Heroku?

A: First, you need to have a Heroku account. After signing up, download and install the Heroku Toolbelt appropriate to your Operating System. Open up the console and type heroku login. It will finish installing the toolbelt and ask you for your credentials. More details on Heroku Toolbelt page.

  1. Set an environment variable by running
heroku config:set FOOD2FORK_KEY=<your-api-key>
  1. Add the following to your Gemfile:
group :production do
  gem 'pg'
  gem 'rails_12factor'
end

a. Find where gem 'sqlite3' is on Gemfile and move it to a group, like the following: group :development, :test do gem 'sqlite3' end

b. Run bundle --without production

NOTE: You should not make changes on Gemfile before submitting your work to be graded. Consider deploying your app to Heroku after you pass the assignment.

  1. If you have not yet done so, initialize and commit to git:
git init
git add .
git commit -m "initial commit"
  1. Create a heroku app
heroku create recipefinder-<a-random-number>
  1. Push to Heroku: git push heroku master

  2. Migrate your database: heroku run rake db:migrate

  3. Visit you application! heroku open

More information on Heroku Dev Center


Q: Why am I getting 'uninitialized constant Capybara' when running RSpec?

A: Together with the spec folder provided, there is also an .rspec file that contains --require spec_helper command which tells RSpec to include spec_helper.rb file located inside the spec folder. The spec_helper.rb includes the necessary Capybara files. If you are getting this error - the chances are you did not copy over the .rspec file.


HTTParty

Q: Why am I getting a SSL error when following the lecture example?

A: You need to turn off the SSL verification by adding

default_options.update(verify: false)

inside Coursera class. You can check the app created for the lecture here: https://github.com/jhu-ep-coursera/fullstack-course1-module3/blob/master/app/models/coursera.rb#L4


Clone this wiki locally