-
Notifications
You must be signed in to change notification settings - Fork 51
Home
Table of Contents
- Q: The rspec test spec/pagination_spec.rb fails
- Q: DELETE method not working for logout and destroy actions
- Q: Getting ExecJS error - could not find a JavaScript runtime
- Q: Object does not support this property or method on Rails Windows
- Q:
routes.rb
not modified when runningrails g scaffold_controller
?
Test spec/pagination_spec.rb
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
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:
<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
.
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)
A: Install [NodeJS] (https://nodejs.org/en/)
Additional References:
- [ExecJS::RuntimeError on Windows] (http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-trying-to-follow-rubytutorial)
- [ExecJS and could not find a JavaScript runtime] (http://stackoverflow.com/questions/6282307/execjs-and-could-not-find-a-javascript-runtime)
- [Installing Node.js via package manager] (https://nodejs.org/en/download/package-manager)
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:
- [Object doesn't support this property or method Rails Windows 64bit] (http://stackoverflow.com/questions/28312460/object-doesnt-support-this-property-or-method-rails-windows-64bit)
A: This might not have been completely clear from the video, but rails g scaffold_controller
only stubs out a new controller with its 7 RESTful actions and the views. For whatever reason, it does NOT modify the routes.rb
file, so you will need to go in there and add resources :resource_name
.