small medium large xlarge

19 Nov 2017, 19:59
Dale Pollitt (3 posts)

I got this error after adding the Sign Out link in Chp 2:

no route matches [get] “/users/sign_out”

after adding the follow code:

<%=​ link_to ​"Log Out"​, destroy_user_session_path, ​method: :delete​ ​%>​

My initial fix was to add the get method to the sign out route through the devise config file located at config/initializers/devise.rb:

config.sign_out_via = [:delete, :get]

This felt wrong to me so I did some more digging. Some sites suggested installing jQuery, but I couldn’t figure out how to do it with webpacker. I ran yarn install jquery and made the following addition to the /app/javascript/packs/application.js file:

import "jquery/dist/jquery.min.js"

This was unsuccessfull. I finally just added the jquery gem and add jQuery through the assets pipeline by adding the following to app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs

I then included this in the application template view with:

<%= javascript_include_tag 'application' %>

I went back and removed the :get method that I added in the devise.rb file and now everything acts normally.

My question is if I should have done this through webpack instead of the assets pipeline, and if so how would I accomplish this? Is there something else that I missed? Thanks!

20 Nov 2017, 12:52
David Copeland (512 posts)

It should work without doing any of that. I just checked out the branch where this happens and it’s working for me, with the latest everything.

Can you try the 2_bootstrap-login/20-use-bootstrap path in the downloadable files and see if that works?

Devise should provide this route and route helper. No need for any JavaScript or any other stuff to do that what the book says.

21 Nov 2017, 01:18
Dale Pollitt (3 posts)

Hey David, appreciate you getting back with me. I was looking through the files you mentioned and think I found the problem. For some reason my app didn’t have the assets/javascripts folder. So I manually created this file and placed the necessary jQuery statements there which got everything working. I noticed yours had the following statement:

//= require rails-ujs

I removed jQuery from my gems file and ran bundle install and gem remove jquery-rails. I included the rails-ujs statement in my application.js file in the assets folder and everything works normally. I’m not exactly sure why my files weren’t the same if it was boilerplate code, but that issue is now solved solved. Time to press on through the Postgres queries chapter. Fun book so far, thanks!

21 Nov 2017, 02:10
David Copeland (512 posts)

That is weird. There’s args you can give to rails new to avoid JavaScript, but I don’t think they are on by default. The rails-ujs stuff is baked into Rails and is vanilla JavaScript that powers stuff, including submitting links that are the DELETE method (since it does this via Ajax). This is all new in Rails 5.1; prior to that it was all based on jQuery.

22 Nov 2017, 16:33
Dale Pollitt (3 posts)

I see what happened. I am using RubyMine as my editor. There is an option to configure javascript for the project. I chose ‘skip’ instead of ‘default’ which I believe used the no javascript option as you stated. I built a new project with ‘default’ and all of the boilerplate code is there. Just pointing this out in case it bites anyone else. Thanks for the assist!

You must be logged in to comment