Skip to content
Kalman Hazins edited this page Mar 26, 2019 · 45 revisions

FAQs - Module 3

Important note: The course was designed to work with Rails 4.2.3. If you're encountering trouble submitting your application, please make sure you're not using Rails 5.0. You can create a 4.2.3 app with:

rails _4.2.3_ new application_name

Please make sure that you are using Ruby 2.2.3 (or a more recent version in the 2.2 series). Ruby 2.3 is not officially supported while Ruby 2.4 is confirmed to be incompatible with Rails 4.2.3.

Recipe Hunter

Creating your First Application

Practice Assignment

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

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

For OSX

echo 'export FOOD2FORK_KEY = "Your API Key"' >> ~/.bash_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.

Notice that usually, you would not have to have the server up and running separately, but because we are using blackbox testing here - you do.


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. Create a heroku app
heroku create recipefinder-<a-random-number>
  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. 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.


Q: I am unable to install gem 'pg'

A: You don't really need pg gem to be installed in your local environment (since you are running in development mode and working with sqlite). The gem is used in production by Heroku, that is not going to have a problem installing it.

You can just

bundle install --without production

Q: Why am I getting a Malformed feedback message from the grader?

A1: You get this error message if you have puts or print statements in your code. Remove those statements and then resubmit. A2: Your application may have been generated using Rails 5, which is incompatible with the grader.

Q: How can I find out if my application has been generated using Rails 5?

A: Rails 5 will be referenced in the Gemfile that is generated as part of the application, replacing this file with the Gemfile given for the assignment (using Rails 4.2) will not work, as the rest of the application is still incompatible with Rails 4. There will also be extra files like config/initializers/new_framework_defaults.rb.

Creating your First Application

Q: sqlite error

I am getting some kind of a sqlite installation error

A: The new version of sqlite is hard to install on some platforms. Therefore, after creating your Rails app, update your Gemfile to say

gem 'sqlite3', '1.3.13'

instead of just

gem 'sqlite'

Then, run bundle update.

Q: Error with html erb file for greeter

I modified my hello.html.erb exactly like it appears in the video and tried to run

http://localhost:3000/greeter/hello

to see it, but I get the following error:

Showing C:/Sites/my_first_app/app/views/layouts/application.html.erb where line #5 raised:

TypeError: unsupported property or method in object.

Rails.root: C:/Sites/my_first_app

What am I doing wrong?

A: Install Node.js and restart your computer and the problem should be fixed

https://github.com/jhu-ep-coursera/fullstack-course1-module1/wiki#q-how-to-fix-the-execjsprogramerror

Q: Why am I seeing cliver dependency error when I run rspec?

I get the following error when I run rspec:

"Cliver::Dependency::NotFound:

Could not find an executable at given path 'c:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.EXE'.If this path was not specified explicitly, it is probably a bug in Cliver."

A: Make sure that the folder for phantomjs folder is under a folder which doesn't have spaces in it. For example, c:/phantomjs/phantomjs-2.1.1-windows/bin is OK.

Practice Assignment

Q: Should I disable WebMock for the tests to pass?

A: No. The error WebMock::NetConnectNotAllowedError is in fact related to the request being made to Food2Fork using wrong parameters and/or path.

When you get that error, check two things:

  1. The query argument

According to the API Documentation, one of the accepted parameters is named q (not query). This means that, "HTTP GET request must have the "q=keyword" query argument" (Technical Requirement #4).

  1. The argument passed to base_uri

In the same Technical Requirement #4, it says that the query should be to the "/search" route. The tests were designed in a way that "/search" should be passed to the GET request, and not to base uri.

One of the tests will concatenate the base_uri + '/search', so it would cause the test to have http://food2fork.com/api/search/search and it would no be valid.


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


Q: Did Coursera API Change?

A: Yes. See the following https://building.coursera.org/developer-program 🎆