Skip to content
Natalja-Olefire edited this page Oct 31, 2016 · 3 revisions

Frequently Asked Questions (FAQs) - Course 3 Module 3

Table of Contents

Q: How to fix the "ExecJS::ProgramError"? Also why is PUT/DELETE requests no longer working?

A: There is an incompatibility between recent versions of the CoffeeScript gem and Windows 64 bit. To fix it, you need to download and install NodeJS Also install the gem coffee-script-source any version except for 1.9.0 (such as 1.10.0 or 1.8.0) After installing, you will need to restart the console.

Note: Many Internet posts will tell you to do change application to default in views/layouts/application.html.erb. That will work only for GET and POST requests, but will break for other request methods like PUT, DELETE.

The symptom of the break is that PUT and DELETE method requests don't work even though actual route defined as a DELETE/PUT but a GET request is being made which does not exist.

The main issue is as follows:

  • Browsers support only GET and POST methods, so how do you tell the server that this is not a post/get but a delete instead?
  • Rails uses something called jquery_ujs (unobtrusive javascript) to intercept a regular request to the server and insert a hidden parameter data-method=delete.
  • If you don't include application.js, jquery_ujs doesn't get included and the magic/interception doesn't not happen which results in a regular get request, which doesn't delete anything since it never gets to the destroy method.

See:

Back To Top

Q: What is aggregate().pipeline method?

A: Take a step back from the the aggregate function and you will notice you are passing in an array of hash({}) elements. That is the "pipeline" and you can access that array of hashes{} after executing aggregate([...]) using the pipeline method.

  > Place.collection.find.aggregate([]).pipeline
   => []
  > query=Place.collection.find.aggregate([
    {:$match=>{:foo=>"bar"}}]).pipeline
   => [{:$match=>{:foo=>"bar"}}]

  > p=[{:$match=>{:foo=>"bar"}}]
  > query=Place.collection.find.aggregate(p)
  > query.pipeline << {:limit=>1}
  > query.pipeline
   => [{:$match=>{:foo=>"bar"}}, {:limit=>1}]

Feel free to work with the array before passing to aggregate([]) or the array after calling aggregate([]) using the .pipline getter.

Back To Top

Q: I have HTTP response code 422 during some tests from web_registration_spec.rb execution. What should I do with it?

A: Some students experience getting HTTP response code 422 during tests from web_registration_spec.rb execution. You can see something like this in your console:

>     Failure/Error: expect(page.status_code).to be < 400
>        expected: < 400
>             got:   422
>      # ./spec/web_registration_spec.rb:41:in `block (3 levels) in <top (required)>'
>      # ./spec/web_registration_spec.rb:17:in `block (2 levels) in <top (required)>'

>     Finished in 0.55082 seconds (files took 2.74 seconds to load)
>     1 example, 1 failure

>     Failed examples:

>     rspec ./spec/web_registration_spec.rb:35 # Module #3 Web Racer/Race Registration 
>     rq02 racer#create_entry route will create a registration in the db

Adding following to your application controller will fix this error:

>     # app/controllers/application_controller.rb
>     protect_from_forgery with: :null_session

Back To Top