0

I have a problem with a Rails app deployed on Heroku.

I have this link in the _header.html.erb file:

...
<li><%= link_to "Log out", logout_path, method: :delete %></li>
...

My logout_path is this one when typing rails routes:

logout    DELETE      /logout(.:format)           sessions#destroy

Now it works just right on local, but on Heroku it just doesnt. The problem is that on Heroku it tries to infer a GET on the logout path:

Heroku logs:

2018-08-17T16:34:16.490731+00:00 app[web.1]: (...) Started GET "/logout" for 84.147.254.28 at 2018-08-17 16:34:16 +0000
2018-08-17T16:34:16.491804+00:00 app[web.1]: (...) ActionController::RoutingError (No route matches [GET] "/logout"):
2018-08-17T16:34:16.492143+00:00 app[web.1]: (...) vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'

Local logs:

Started DELETE "/logout" for 127.0.0.1 at 2018-08-17 18:44:51 +0200

Can someone help me with this, I dont know why it does that allthough I seemingly did everything like it should be done.

Thank you,

Jaiel

EDIT:

my application.js

//= require jquery
//= require bootstrap
//= require rails-ujs
//= require turbolinks
//= require_tree .
Ilja KO
  • 1,272
  • 12
  • 26
  • 1
    Seems like you JavaScript files are not loading. Does you asset pipeline work? – spickermann Aug 17 '18 at 17:17
  • I am a beginner I dont know how to check if the asset pipeline is working or not. I edit the post to provide how my application.js looks like. Also the assets are allways cleaned and precompiled when I deploy to Heroku so I dont know if I still make someting wrong – Ilja KO Aug 17 '18 at 17:26
  • This may help https://stackoverflow.com/questions/23256322/sign-out-working-locally-but-not-working-on-heroku – Pavan Aug 17 '18 at 18:15
  • I reordered the require statements, I have the rails-12factor gem installed It doesnt work at all anything that I tried doesnt work....Im giving up on Heroku. Its not understandable for me why some had their problem solved by jsut rearranging their require statements in the first place. Is it crazy to say that soemthing jsut doesnt work quite right on Heroku if such not obvious problem occur? – Ilja KO Aug 17 '18 at 18:48
  • The issue isn't heroku it's running on production. Try to first generate assets locally by running `RAILS_ENV=production rake assets:precompile` and then run your server in production mode `RAILS_ENV=production SECRET_KEY_BASE=foo RAILS_SERVE_STATIC_FILES=1 RAILS_LOG_TO_STDOUT=1 rails s` and you'll likely see the same behavior . Use your browser's console to see if you're getting JS errors or if it cannot find or load an asset file. Inspect source and make sure all assets are reachable. Once this works locally in prod mode it will work on Heroku (or anywhere else you want to deploy). – Schneems Aug 27 '18 at 20:28
  • allright I ran the server in production and yes Ive got the same problems there. I can laod pictures from my image folders so the asset pipeline should work. All I want is the JavaScript to work properly. But it doesnt – Ilja KO Aug 27 '18 at 23:01
  • also checked the source and there are a lot of JS files not loaded in production which are laoded in development env. and I get 3 JS errors in prod env which I dont get in dev env, but those JS files are auto generatate by rails I guess because I haven touched them – Ilja KO Aug 28 '18 at 05:32
  • and also : Everything works jsut fine if I paste all the contents f my /config/environments/development.rb file ind my /config/environments/production.rb :) happy times :) – Ilja KO Aug 28 '18 at 05:34

1 Answers1

0

I identified the error now: as I allready knew it was a JS error. The problem on my side was that there were too many JS files in my public/assets folder. I just had to delete my assets folder and precompile the assets again. Before I had like 6 JS files and 3 CSS files now after the deletion and precompilation only 1 JS and 1 CSS file nothing was conflicting or causing bugs anymore :)

Now my App runs perfectly in productio. Allthough now there is still the error with Heroku because I cant seem to get rid of the assets folder content because everytime I delete that oflder through bash cli and precompile the assets, the old JS assets keep popping up again.

If someone figures out a solution comment here, but otherwise this was the solution to my problem.

Ilja KO
  • 1,272
  • 12
  • 26