[WellRailed] Fix or no fix for strange IE respond_to accept headers bug

65 views
Skip to first unread message

ptorrsmith

unread,
Apr 15, 2010, 8:43:43 PM4/15/10
to WellRailed, dar...@catalyst.net.nz
We've bumped into this on a job, where IE accept headers say they
respond to anything, so it responds to the first call in the
respond_to block.

Saw Koz put a fix in ages ago but it was retracted shortly after
(http://github.com/rails/rails/commit/
2f4aaed7b3feb3be787a316fab3144c06bb21a27)

So we have manually put the following

config.action_controller.use_accept_header = false

in the config/environment.rb (thanks to
http://paul.stadig.name/2009/02/rails-respondto-ie6-and-accept-header.html)

We use formatted urls (e.g. /people/1.js) to support non html calls,
so feel safe using this approach.

Anyone know of any problems with doing this?

Seems like both a bug in IE and a problem with respond_to, with
neither wanting to budge? :-)

--
You received this message because you are subscribed to the Google Groups "WellRailed" group.
To post to this group, send email to wellr...@googlegroups.com.
To unsubscribe from this group, send email to wellrailed+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wellrailed?hl=en.

Jeremy Olliver

unread,
Apr 15, 2010, 9:17:41 PM4/15/10
to wellr...@googlegroups.com
I've had a problem with this before, and the fix for me was to ensure the html response was declared before the js response.

eg.

# Incorrectly displays JS when should be redirecting
responds_to do |format|
  format.js { render :action => 'update' }
  format.html { redirect_to :action => 'show' }
end

# Works correctly
responds_to do |format|
  format.html { redirect_to :action => 'show' }
  format.js { render :action => 'update' }
end

Not sure if this will help out in your case, but it worked for me.

Cheers,
Jeremy
--
Jeremy Olliver
Developer
Heaps!
More out of life

Michael Koziarski (nzkoz)

unread,
Apr 15, 2010, 9:21:26 PM4/15/10
to WellRailed
The problem you're both having is that Internet Explorer sends a
ludicrous Accept header in a few situations. From memory it's things
like:

# The flash plugin requesting the url
# Opening the page in a new window

etc.

The header says "I consider xml, html, javascript, word documents and
anything else as equal" and in those situations rails will send your
first format to break a tie.

I personally would strongly recommend disabling the accept header,
otherwise your site becomes unusable once you have a public website
with dozens of IE users each with a different permutation of browser
helpers.

On Apr 16, 1:17 pm, Jeremy Olliver <jeremy.olli...@gmail.com> wrote:
> I've had a problem with this before, and the fix for me was to ensure the
> html response was declared before the js response.
>
> eg.
>
> # Incorrectly displays JS when should be redirecting
> responds_to do |format|
>   format.js { render :action => 'update' }
>   format.html { redirect_to :action => 'show' }
> end
>
> # Works correctly
> responds_to do |format|
>   format.html { redirect_to :action => 'show' }
>   format.js { render :action => 'update' }
> end
>
> Not sure if this will help out in your case, but it worked for me.
>
> Cheers,
> Jeremy
>
> On 16 April 2010 12:43, ptorrsmith <ptorrsm...@gmail.com> wrote:
>
>
>
>
>
> > We've bumped into this on a job, where IE accept headers say they
> > respond to anything, so it responds to the first call in the
> > respond_to block.
>
> > Saw Koz put a fix in ages ago but it was retracted shortly after
> > (http://github.com/rails/rails/commit/
> > 2f4aaed7b3feb3be787a316fab3144c06bb21a27)
>
> > So we have manually put the following
>
> > config.action_controller.use_accept_header = false
>
> > in the config/environment.rb  (thanks to
> >http://paul.stadig.name/2009/02/rails-respondto-ie6-and-accept-header...
> > )
>
> > We use formatted urls (e.g. /people/1.js) to support non html calls,
> > so feel safe using this approach.
>
> > Anyone know of any problems with doing this?
>
> > Seems like both a bug in IE and a problem with respond_to, with
> > neither wanting to budge? :-)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "WellRailed" group.
> > To post to this group, send email to wellr...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > wellrailed+...@googlegroups.com<wellrailed%2Bunsubscribe@googlegrou ps.com>
> > .

jemmyw

unread,
Apr 16, 2010, 6:35:35 PM4/16/10
to WellRailed
I've come across this a few times recently. My solution was to make
sure to specify :format => 'html' in any links to the action in
question (i.e. user_path(@user, :format => 'html')). Perhaps a bit
more work, but it definitely makes it clear where it's going.

On Apr 16, 1:21 pm, "Michael Koziarski (nzkoz)" <koziar...@gmail.com>
wrote:
> > > "WellRailed" group.> > To post to this group, send email towell...@googlegroups.com.
> > > To unsubscribe from this group, send email to> >wellrailed+...@googlegroups.com<wellrailed%2Bunsubscribe@googlegrou ps.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/wellrailed?hl=en.
>
> > --
> > Jeremy Olliver
> > Developer
> > Heaps!
> > More out of life
>
> > --
> > You received this message because you are subscribed to the Google Groups "WellRailed" group.> To post to this group, send email towell...@googlegroups.com.> To unsubscribe from this group, send email towellrailed...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/wellrailed?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "WellRailed" group.To post to this group, send email towell...@googlegroups.com.To unsubscribe from this group, send email towellrailed...@googlegroups.com.

ptorrsmith

unread,
Apr 18, 2010, 6:45:10 PM4/18/10
to WellRailed
We've not done the the :format -> 'html' bit, but we are ensuring all
our ajax calls are have '.js' at the end of them.
Plus with the "config.action_controller.use_accept_header = false" in
the config/environment.rb, things seem to be behaving now.

Interestingly enough, we were using a jquery in-place-editor (http://
code.google.com/p/jquery-in-place-editor/) which was responding in the
format.html block (it's not expecting javascript back, just the text
of the updated value). After we put in the use_accept_header = false
bit, it stopped working, and turned out that it now was responding to
the format.js block. Strange, as the accept headers (which the
environment config now says to ignore) is 'text/html' and the post
request url does not have .js on it.
> > > > To unsubscribe from this group, send email to> >wellrailed+...@googlegroups.com<wellrailed%2Bunsubscribe@googlegro u ps.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/wellrailed?hl=en.
>
> > > --
> > > Jeremy Olliver
> > > Developer
> > > Heaps!
> > > More out of life
>
> > > --
> > > You received this message because you are subscribed to the Google Groups "WellRailed" group.> To post to this group, send email towell...@googlegroups.com.> To unsubscribe from this group, send email towellrailed...@googlegroups.com.
> > > For more options, visit this group athttp://groups.google.com/group/wellrailed?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "WellRailed" group.To post to this group, send email towellrai...@googlegroups.com.To unsubscribe from this group, send email towellrailed...@googlegroups.com.

James Moriarty

unread,
Apr 28, 2010, 7:04:07 AM4/28/10
to WellRailed
Had a similar problem a few months ago. Appending .js onto the url
seems safer but you could try something like this?

jQuery.ajaxSetup( { 'beforeSend': function(xhr)
{ xhr.setRequestHeader("Accept", "text/javascript" ) } } )

This might not be good if your loading html via ajax?
Reply all
Reply to author
Forward
0 new messages