Archive for June, 2008

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 HTTP_REFERER, which IE does not do.  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