H. Wade Minter
2008-May-15 01:05 UTC
Why are IE6 and Firefox rendering different formats from the same URL?
I have a controller action in my Rails 2.0.2 app that looks like this: def matrix @shows = Show.find(:all) @players = Player.find(:all) respond_to do |format| format.html format.xls do set_excel_headers(headers,"matrix-#{@show_year}- #{@show_month}.xls") end end end In Firefox, this works exactly as expected - when I go to /signups/ matrix, I get the HTML format rendered. If I go to /signups/ matrix.xls, I get the Excel version. However, when I do the same thing on IE6/XP, I get the Excel format rendered for both. /signups/matrix tries to download the Excel file. The log doesn''t show anything odd that I can tell: Processing SignupsController#matrix (for 192.168.119.1 at 2008-05-14 20:03:57) [GET] Session ID: 39a88d1fff075058276e65d67136f7dd Parameters: {"action"=>"matrix", "controller"=>"signups"} [....] Completed in 0.23381 (4 reqs/sec) | Rendering: 0.03932 (16%) | DB: 0.09844 (42%) | 200 OK [http://192.168.119.1/signups/matrix] I''m stumped - does anyone know why this would be happening? --Wade --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ix Quic
2008-May-15 13:10 UTC
Re: Why are IE6 and Firefox rendering different formats from the same URL?
The key to this behavior is the Accept header of the HTTP request. You can check it in Rails with request.headers[''HTTP_ACCEPT''] (see ActionController::AbstractRequest). IE6 prefers MS Office content (Excel, Powerpoint, Word) over HTML: ... Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */* ... (I got this from http://www.ibm.com/developerworks/xml/library/x-tipapachexhtml/index.html as I don''t have IE6 installed.) So (X)HTML mimetypes don''t even appear explicitly, they''re caught by the wildcard */* and have the lowest priority. Very strange, but this is how Microsoft wanted it to be. They fixed this in the meantime. The Internet Explorer 8 beta header says simply: Accept: */* To be sure to get the HTML rendering, say /signups/matrix.html . I guess you could also tinker with your HTTP server settings to give the HTML mimetypes higher priority. H. Wade Minter wrote:> I have a controller action in my Rails 2.0.2 app that looks like this: > > def matrix > @shows = Show.find(:all) > @players = Player.find(:all) > respond_to do |format| > format.html > format.xls do > set_excel_headers(headers,"matrix-#{@show_year}- > #{@show_month}.xls") > end > end > end > > In Firefox, this works exactly as expected - when I go to /signups/ > matrix, I get the HTML format rendered. If I go to /signups/ > matrix.xls, I get the Excel version. > > However, when I do the same thing on IE6/XP, I get the Excel format > rendered for both. /signups/matrix tries to download the Excel file. > > The log doesn''t show anything odd that I can tell: > > Processing SignupsController#matrix (for 192.168.119.1 at 2008-05-14 > 20:03:57) [GET] > Session ID: 39a88d1fff075058276e65d67136f7dd > Parameters: {"action"=>"matrix", "controller"=>"signups"} > > [....] > > Completed in 0.23381 (4 reqs/sec) | Rendering: 0.03932 (16%) | DB: > 0.09844 (42%) | 200 OK [http://192.168.119.1/signups/matrix] > > > I''m stumped - does anyone know why this would be happening? > > --Wade > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
H. Wade Minter
2008-May-15 23:56 UTC
Re: Why are IE6 and Firefox rendering different formats from the same URL?
Thanks for the tip - I went in and changed application/vnd.ms-excel to application/octet-stream in the initializer/mime_types.rb file, and it seems to be performing expected behavior now. Thanks again! --Wade On May 15, 2008, at 8:10 AM, Ix Quic wrote:> > The key to this behavior is the Accept header of the HTTP request. > You can > check it in Rails with request.headers[''HTTP_ACCEPT''] (see > ActionController::AbstractRequest). > > IE6 prefers MS Office content (Excel, Powerpoint, Word) over HTML: > ... > Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, > application/vnd.ms-excel, > application/msword, application/vnd.ms-powerpoint, */* > ... > (I got this from > http://www.ibm.com/developerworks/xml/library/x-tipapachexhtml/index.html > as I don''t have IE6 installed.) > > So (X)HTML mimetypes don''t even appear explicitly, they''re caught by > the > wildcard */* and have the lowest priority. > > Very strange, but this is how Microsoft wanted it to be. They fixed > this in > the meantime. The Internet Explorer 8 beta header says simply: > Accept: */* > > To be sure to get the HTML rendering, say /signups/matrix.html . I > guess > you could also tinker with your HTTP server settings to give the HTML > mimetypes higher priority. > > > > H. Wade Minter wrote: >> I have a controller action in my Rails 2.0.2 app that looks like >> this: >> >> def matrix >> @shows = Show.find(:all) >> @players = Player.find(:all) >> respond_to do |format| >> format.html >> format.xls do >> set_excel_headers(headers,"matrix-#{@show_year}- >> #{@show_month}.xls") >> end >> end >> end >> >> In Firefox, this works exactly as expected - when I go to /signups/ >> matrix, I get the HTML format rendered. If I go to /signups/ >> matrix.xls, I get the Excel version. >> >> However, when I do the same thing on IE6/XP, I get the Excel format >> rendered for both. /signups/matrix tries to download the Excel file. >> >> The log doesn''t show anything odd that I can tell: >> >> Processing SignupsController#matrix (for 192.168.119.1 at 2008-05-14 >> 20:03:57) [GET] >> Session ID: 39a88d1fff075058276e65d67136f7dd >> Parameters: {"action"=>"matrix", "controller"=>"signups"} >> >> [....] >> >> Completed in 0.23381 (4 reqs/sec) | Rendering: 0.03932 (16%) | DB: >> 0.09844 (42%) | 200 OK [http://192.168.119.1/signups/matrix] >> >> >> I''m stumped - does anyone know why this would be happening? >> >> --Wade >> >> >>> >> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---