Skip to content
Faacy Farook edited this page Jan 17, 2016 · 11 revisions

Frequently Asked Questions (FAQs) - Course 2 Module 4


Table of Contents


Q: The rspec test spec/pagination_spec.rb fails

Test rspec spec/pagination_spec.rb fails fails with the following error message:

Failure/Error: click_link("#{p+1}", :href => "/?page=#{p+1}")

Capybara::ElementNotFound:

Unable to find link "2" with href "/?page=2"

# ./spec/pagination_spec.rb:40:in `block (4 levels) in <top (required)>'

# ./spec/pagination_spec.rb:38:in `block (3 levels) in <top (required)>'

# ./spec/pagination_spec.rb:13:in `block (2 levels) in <top (required)>'

But when manually going to the other pages on the browser, there is no problem.

A: In the routes.rb set the root at the beginning

Rails.application.routes.draw do

    root to: 'todo_lists#index'
    ...
end


For example, verify that when you login to the site, in the pagination control,
that the HTML for the link to the second page is as following:

```html
<a rel="next" href="/?page=2">2</a>

Note that the rspec test is looking for the link to be /?page=2 and not /todolists?page=2.

Back To Top


Q: DELETE method not working for logout and destroy actions

The logout link is executing as a GET rather then a DELETE even though it is correctly defined in routes.rb and view.

For example, in the routes.rb the route is defined as:

delete "/logout" => "sessions#destroy", as: "logout"

In the view the logout link is defined as:

<%= link_to "Logout", logout_path, method: :delete, data: { confirm: 'Are you sure?' } %>

The same thing is also happening when deleting an item or a list. It just redirects to the show for that item or list.

A: The issue is in application.html.erb line 6:

<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>

which must to be:

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Note application instead of default. Otherwise none of the DELETE routes will work. It is required because it includes javascript code that allows a DELETE request (to be made via a GET request). Otherwise it will be just a GET request.

Also see:

  • [Q: Getting ExecJS error - could not find a JavaScript runtime] (#q-getting-execjs-error---could-not-find-a-javascript-runtime)
  • [Q: Object does not support this property or method on Rails Windows] (#q-object-does-not-support-this-property-or-method-on-rails-windows)

Back To Top


Q: Getting ExecJS error - could not find a JavaScript runtime

A: Install [NodeJS] (https://nodejs.org/en/)

Additional References:

Back To Top


Q: Object does not support this property or method on Rails Windows

A: If you are getting the Object does not support the property or method error, then use the latest gem for "coffee-script-source" (like 1.10.0) - anything other than version 1.9.x

Additional References:

Back To Top


Clone this wiki locally