Forum: Ruby on Rails Rails and Firefox on crack with redirections

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-04-04 16:50
Hi,

Rails and/or Firefox are driving me nuts.

I have a products_controllers with 2 actions: index and show.

- On the index action a session is set to create an order if user has no
order yet.
- On that index page, user can click on a link that will bring him to
the show action of a product where payment buttons are displayed.
- The show action is protected by a before_filter login_required, and a
before filter for checking if a session[:order_id] is present, if not he
goes to index action.
- After logging in, user is redirected to show action, payment buttons
appear, and his session[:order_id] is set to nil.

All is fine up to here. So now while on show action, if user hits the
reload button, as his session is empty, he will go to index page. That
works.

But now, hang on tight, back on index page, if user click the refresh
button, for some mysterious reason, he goes to the show page he
previously visited!!! How is that possible???

And even more strange, while on the index page, if user hits enter key
in the address bar, then the user doesn't get redirected to show page,
but stays on index page!?

Is that a buggy behavior from Firefox or what???
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-04-04 17:03
> Is that a buggy behavior from Firefox or what???

Damn! It's Firefox going nuts! I tested with Safari and I don't have
that problem... Grrr that's very bad!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-04 18:17
(Received via mailing list)
On Apr 4, 3:50 pm, Fernando Perez <rails-mailing-l...@andreas-s.net>
wrote:
> But now, hang on tight, back on index page, if user click the refresh
> button, for some mysterious reason, he goes to the show page he
> previously visited!!! How is that possible???

>
> And even more strange, while on the index page, if user hits enter key
> in the address bar, then the user doesn't get redirected to show page,
> but stays on index page!?
>
> Is that a buggy behavior from Firefox or what???

Without going into the specifics of what you have or have not done, I
think you might need to do a little more digging: is firefox
requesting the wrong page from your app, is it requesting the right
page but doing something funny, is it just serving a page from its
cache ?

Fred
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-04-04 19:01
> Without going into the specifics of what you have or have not done, I
> think you might need to do a little more digging: is firefox
> requesting the wrong page from your app, is it requesting the right
> page but doing something funny, is it just serving a page from its
> cache ?
>
> Fred

Firefox requests the page that was protected by the before_filter.
Safari doesn't do that.

It's only when I use the refresh button (or ctrl+r shortcut) that
firefox instead of refreshing the current index page, goes to the former
/show/my_url.

If I "refresh" manually the index page by simply pressing the Enter key
when focus is in the address bar, it doesn't act stupidly.
775dc78d64c87ae51db522529c3784e9?d=identicon&s=25 Phillip (Guest)
on 2009-04-05 14:54
(Received via mailing list)
This could be handy:

<table style = "font-size:small;">
<% req = request.env
   req.each do |key,value| %>
  <tr><td><%= "#{key}" %></td><td><%= "#{value}" %></td></tr>
  <% end %>
</table>


On Apr 4, 1:01 pm, Fernando Perez <rails-mailing-l...@andreas-s.net>
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-04-06 14:05
Phillip wrote:
> This could be handy:
>
> <table style = "font-size:small;">
> <% req = request.env
>    req.each do |key,value| %>
>   <tr><td><%= "#{key}" %></td><td><%= "#{value}" %></td></tr>
>   <% end %>
> </table>

Interesting idea, however I couldn't find any data concerning the
redirection to the show page.
40448fd80f5ca8b95db5f107c1a6372b?d=identicon&s=25 Skaurus (Guest)
on 2009-04-06 14:11
(Received via mailing list)
On 4 апр, 18:50, Fernando Perez <rails-mailing-l...@andreas-s.net>
wrote:
> - The show action is protected by a before_filter login_required, and a
> button, for some mysterious reason, he goes to the show page he
> previously visited!!! How is that possible???
>
> And even more strange, while on the index page, if user hits enter key
> in the address bar, then the user doesn't get redirected to show page,
> but stays on index page!?
>
> Is that a buggy behavior from Firefox or what???
> --
> Posted viahttp://www.ruby-forum.com/.


Did you used redirect_to or just called one action from another?
First approach should be used.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-04-06 14:39
> Did you used redirect_to or just called one action from another?
> First approach should be used.

At which step?

On index page, user clicks on a link like: mysite.com/products/product-1

products_controller/show is protected by a before_filter which
redirect_to a signup/login page (using restful_auth). When user is
identified, redirect_back_or_default('/') will redirect the user to
mysite.com/products/product-1 and clear session[:return_to]

On the show page, if user hits the reload button, a redirect_to will
bring him back to the index. Now here is the split between Firefox and
Safari:

- on index page, with Firefox, if user hits refresh button, he goes back
to /products/product-1, that's incorrect behavior.

- on index page, with Safari, if user hits refresh button, the index
page gets refreshed. That's the expected behavior.

So whose fault is it? Rails or Firefox?

Can you please be more accurate? I don't see at which step I should be
using a redirect_to instead of a call, as I already use redirections
where they are required (I think).

Best regards,
This topic is locked and can not be replied to.