Rails redirect_to :back in Internet Explorer

Today I realized that the rails command redirect_to :back does not work in Internet Explorer because redirect_to :back depends on the HTTP_REFERER http header, which IE does not send. I was capturing an onclick event with jQuery and was able to sending along the current URL as a query string, which provided an easy way around this limitation.

In the view:

<script>
    $jQuery('#myLink').click(function(){
        window.location.href = 'theDestinationPage/?current_url=' + document.location ;
    })
</script>

In the controller:

def myAction
    .....
    redirect_to params[:current_url]
end
This entry was posted in rails. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted April 2, 2009 at 8:32 am | Permalink

    Cool! It did help me. thanks! :D

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>