unable to navigate away from page via browser back button - ruby-on-rails

When these partials are loaded in the browser I am unable to navigate away from the page via the browser back button. The page stays the same but the url changes.
What could be causing this?
match '/signup', to: 'users#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'get'
# /users/new
def new
#user = User.new
render partial: "new", layout: false
end
# /sessions/new
def new
render partial: "new", layout: false
end
Here's my stack. This is from just clicking the signin link once.
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as */*
Processing by SessionsController#new as */*
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Completed 200 OK in 3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Started GET "/signin" for 127.0.0.1 at 2014-03-26 19:57:46 -0700
Processing by SessionsController#new as HTML
Processing by SessionsController#new as HTML
Rendered sessions/_new.html.erb (0.8ms)
Rendered sessions/_new.html.erb (0.8ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)
Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms)

Do you have a before filter redirecting public access to sessions#new? Have you defined /signin as a route?

I might be wrong, but as I wrote in the comment while ago I had a customer that used Turbolinks on Rails 3.2.12 and a group of customized JS libraries. The Turbolinks was causing a lot of issues such as double submitting and one of them was a similar thing to what you have mentioned. I had 3 choices:
1- Take out Turbolinks (my temp solution, until I showed the team TL was causing it)
2- Change the JS lib dependencies
3- Update the Rails App to 4.x latest. (I did this finally, it wasn't too bad)
In case if I was wrong and your case and setup was not similar to mine, here is a good thread on Github that some guy tries to solve it and still seems to be open.
https://github.com/rails/turbolinks/issues/256

Check your parameters :
Processing SESSION::SESSION#new (for 127.0.0.1 at 2014-04-04 13:50:03) [POST]
Parameters: {"authenticity_token"=>"XXXXX=", "param1"=>"1"}
Well in your log you will see what params you are sending if it is not sending what you want create params according to your columns or what you want to keep.
If you want create a back button you could try this:
link_to_function "Back", "history.back()"
Check your action form maybe you are sending other url
<% form_tag :controller=>"sessions",:action=>"new" do %>
<% #user.each do |user| %>
<%= user.name %>
<%= user.lastname %>
<% end %>
<% end %>

Related

Can't read local geojson

Trying to read a geojson in Rail. Specifically
/public/switzerland.geojson
Console error:
Started GET "/oladvancedview" for ::1 at 2023-02-02 16:42:44 -0800
Processing by DemoController#oladvancedview as HTML
Rendering layout layouts/application.html.erb
Rendering demo/oladvancedview.html.erb within layouts/application
Rendered demo/oladvancedview.html.erb within layouts/application (Duration: 0.3ms | Allocations: 160)
Rendered layout layouts/application.html.erb (Duration: 3.0ms | Allocations: 2803)
Completed 200 OK in 4ms (Views: 3.7ms | Allocations: 3039)
Started GET "/Users/gscar/Documents/Ruby/RailsTrials/os-stimulus-mapping/public/switzerland.geojson" for ::1 at 2023-02-02 16:42:44 -0800
ActionController::RoutingError (No route matches [GET] "/Users/gscar/Documents/Ruby/RailsTrials/os-stimulus-mapping/public/switzerland.geojson"):
rails routes
public_switzerland GET /public/switzerland(.:format) public#switzerland {:format=>"json"}
routes.rb get 'public/switzerland', defaults: { format: 'json' }
xx.html.erb <% path = File.join Rails.root, 'public', 'switzerland.geojson' %
Passing with Stimulus
<div id="avmap"
data-controller="ol-advanced-view"
data-ol-advanced-view-target="avmap"
data-ol-advanced-view-url-value = "<%= path %>"
style="height:400px" >
</div>
No Javascript errors in stimulus controller.
Clueless what is going on. How do I read this file? Thank you for any ideas?

Rails Receives Repetitive Requests on One Request

My route is as follows:
Rails.application.routes.draw do
get 'courses' => 'application#index'
get 'check_db' => 'application#check_db'
root 'application#index'
end
And my application#check_db is
def check_db
p "test"
redirect_to root_path
end
When I visit /check_db on my browswer (tried both in Chrome and Safari), if working properly, it should GET "/check_db" and then GET "/". But actually, the log shows that there are four requests, with the above pattern repeated twice (i.e. GET "/check_db", GET "/", GET "/check_db", GET "/"). There is absolutely no code in my application#index that does any other redirection. So why is this?
The situation described above happen most of the times. However, occasionally, it works as expected. I did not change the code in the interim.
If it is in interest, the entire log is pasted below:
Started GET "/check_db" for ::1 at 2017-01-04 17:05:06 -0800
Processing by ApplicationController#check_db as HTML
"test"
Redirected to http://localhost:3000/
Completed 302 Found in 1ms
Started GET "/" for ::1 at 2017-01-04 17:05:06 -0800
Processing by ApplicationController#index as HTML
Rendering application/index.html.erb within layouts/application
[MongoDB query log]
Rendered application/index.html.erb within layouts/application (3.4ms)
Completed 200 OK in 18ms (Views: 16.4ms)
Started GET "/check_db" for ::1 at 2017-01-04 17:05:07 -0800
Processing by ApplicationController#check_db as HTML
"test"
Redirected to http://localhost:3000/
Completed 302 Found in 8ms
Started GET "/" for ::1 at 2017-01-04 17:05:07 -0800
Processing by ApplicationController#index as HTML
Rendering application/index.html.erb within layouts/application
[MongoDB query log]
Rendered application/index.html.erb within layouts/application (4.1ms)
Completed 200 OK in 17ms (Views: 15.0ms)

Started DELETE "/users/sign_out" => Processing by Devise::SessionsController#destroy as HTML => User still logged in

When I click 'log out' I can see that Rails processess the request, but I'm still logged in.
Any clue why this happens? Both locally and on Heroku.
Started DELETE "/users/sign_out" for IP at 2014-11-18 08:32:46 +0000
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"TOKEN"}
Redirected to http://example.com/
Completed 302 Found in 14ms (ActiveRecord: 4.4ms)
Started GET "/" for 84.215.64.133 at 2014-11-18 08:32:47 +0000
Processing by StaticPagesController#blog as HTML
Rendered static_pages/blog.html.slim within layouts/application (0.7ms)
Completed 200 OK in 6ms (Views: 2.9ms | ActiveRecord: 1.6ms)
routes.rb
devise_for :users
From the log when editing a user:
Started PUT "/users" for 84.215.64.133 at 2014-11-18 14:40:30 +0000
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QR/p3BAG+ocmacss5xDjuFDfhFSA+iv6VRK37uA9HcQ=", "user"=>{"mobile"=>"93441707", "email"=>"sss#
strosin.info", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Lagre"}
2014-11-18T14:40:31.095730+00:00 app[web.2]: App 131 stdout: Redirected to http://
The problem disapeared when I cleared the browser cache. (Using Chrome beta).

authenticate_user! hijacking the registrations/create method

The problem I'm having seems to be that Devise's authenticate_#{role}! method is hijacking my registration attempt.
Started GET "/client/sign_up" for 127.0.0.1 at 2012-01-14 12:02:52 +0000
Processing by Client::RegistrationsController#new as HTML
Rendered /Users/robertwwhite/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.3/app/views/devise/shared/_links.erb (1.4ms)
Rendered client/registrations/new.html.haml within layouts/application (97.6ms)
Rendered client/_navigation.html.haml (1.6ms)
Rendered shared/_flash_messages.html.haml (0.1ms)
Completed 200 OK in 126ms (Views: 116.4ms | ActiveRecord: 7.2ms)
Started POST "/client" for 127.0.0.1 at 2012-01-14 12:02:58 +0000
Processing by WishesController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"vq3wgsQeb4eoxhb3sw2Q2kd4edIoOxIfrzJ/WzJUAn0=", "client"=>{"email"=>"bacon#example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Completed 401 Unauthorized in 13ms
Started GET "/client/sign_in" for 127.0.0.1 at 2012-01-14 12:02:58 +0000
Processing by Client::SessionsController#new as HTML
Rendered /Users/robertwwhite/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.3/app/views/devise/shared/_links.erb (1.0ms)
Rendered client/sessions/new.html.haml within layouts/application (16.5ms)
Rendered client/_navigation.html.haml (1.5ms)
Rendered shared/_flash_messages.html.haml (0.3ms)
Completed 200 OK in 60ms (Views: 38.6ms | ActiveRecord: 6.4ms)
I've tried overriding the after_signup_path_for(resource_or_scope) but it seems to be getting ignored.
# app/controllers/application_controller.rb
def after_sign_up_path_for(resource_or_scope)
random_path
end
So as it stands users can't register to the site in the first place. Any ideas?
Have you checked to make sure non of your routes are overriding the default devise routes/methods?
Edited by HaaR for clarity of users with similar problem:
I had the following in my config/routes.rb above my devise_for methods.
match "client" => "wishes#index"
Which was overriding Devise's
devise_for :clients, :path => :client
By moving it below, it gives Devise priority, and still passes the get request to the appropriate controller and action without hijacking the POST requests.

After switching to production, AJAX/Javascript is ignored even with respond_to do |format|

Okay, here's the deal I can't figure out at the moment.
So, I have this action looking like this:
def get
#page = Page.find_by_title(params[:title])
respond_to do |format|
format.html # get.html.erb
format.js # get.js.coffee
end
end
Which, depending on whether it's an AJAX call or a normal GET request, the renders either get.html.erb or get.js.coffee.
In development, that is, as shown by the following log entry:
Started GET "/pages/medien/get" for 127.0.0.1 at 2011-12-11 18:58:31 +0100
Processing by PagesController#get as JS
Parameters: {"title"=>"medien"}
Rendered pages/_get.html.erb (153.0ms)
Rendered pages/get.js.coffee (1185.0ms)
Completed 200 OK in 1230ms (Views: 1220.0ms | ActiveRecord: 5.0ms)
In production the same request and same code results in a log entry like this:
Started GET "/pages/medien/get/" for 91.11.86.230 at 2011-12-11 18:57:44 +0100
Processing by PagesController#get as JS
Parameters: {"title"=>"medien"}
Read fragment views/mypage/pages/medien/get (0.1ms)
Rendered pages/_get.html.erb (0.8ms)
Rendered pages/get.html.erb (0.9ms)
Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.2ms)
I simply don't get why it's even stating that it's processing it as JavaScript but then does not execute the javascript in get.js.coffee without even throwing an error!

Resources