respond_to js and redirect - inconsistent results forwarding JS requirement


I have the following simple piece of code in one of my actions:

respond_to do |format|    format.js { redirect_to basket_url } end

In Safari this works fine and the basket controller's show action is called and returns a rjs response. However in Firefox it calls the show action on basket but instead returns an html response, it doesn't seem to detect the call came from a forwarded js request.

The only way I have found around this to get consistent results is:

respond_to do |format|    format.js { redirect_to formatted_basket_url(:format => :js) } end

Is this correct?

On a related note I've also had instances where the order of the format.js, format.html etc in the respond_to block has influenced what has been rendered (mainly browsing with IE)?? Is there a reason or pattern to this?



I think I might have found a reason, just in case anyone has a similar issue.

I may have misunderstood what was happening on a redirect_to call in the action. I assumed it was an internal redirection within the server between the two actions and it didn't inform the browser, just rendered the end result.

In reality it is sending a normal 302 redirect response to the browser and this is then submitting a new request. It appears on Safari the redirected GET request is inheriting the js accept info from the original request, however on Firefox it doesn't make this link. Hence the reason the formatted_basket_url is needed to force the issue and ensure there is no doubt over which response we need.

At least that's my take on it, if anyone knows different let me know.