{"id":33,"date":"2010-08-02T16:31:13","date_gmt":"2010-08-02T21:31:13","guid":{"rendered":"http:\/\/unixmonkey.net\/?p=33"},"modified":"2010-08-02T16:31:13","modified_gmt":"2010-08-02T21:31:13","slug":"rails-respond_to-rendering-wrong-format-in-ie","status":"publish","type":"post","link":"https:\/\/unixmonkey.net\/?p=33","title":{"rendered":"Rails respond_to rendering wrong format in IE"},"content":{"rendered":"<p>I ran into an interesting issue today where a client viewing my Rails site would go to a link; and instead of seeing the html view rendered, it was skipping right to an alternate format in the respond_to block.<\/p>\n<p>Clicking a link going to \/orders, was instead taking them to \/orders.xls, which I have in a respond_to block like so:<\/p>\n<pre lang='ruby'>\n  def orders\n    @orders = Order.all\n    respond_to do |format|\n      format.html # new.html.erb\n      format.xls   # new.xls.erb\n    end\n  end\n<\/pre>\n<p>The client in question was using Internet Explorer. This provided a major clue.<br \/>\nIt turns out that IE will send an HTTP_ACCEPT header listing all the stuff it can accept in the browser, and thus, because it can accept .xls files, it requests that format.<\/p>\n<p>I&#8217;m experiencing this in a Rails 2.3.8 app, but documentation at railsguides.info states this behavior was changed in Rails 2.2.  Perhaps an older plugin is switching it back on, I&#8217;ll have to investigate.<\/p>\n<p>In any case, adding this line to application.rb solves the problem:<\/p>\n<pre>config.action_controller.use_accept_header = false<\/pre>\n<p>This causes it to behave as expected, where it uses the file extension alone to determine the format when there is a question which format to use.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into an interesting issue today where a client viewing my Rails site would go to a link; and instead of seeing the html view rendered, it was skipping right to an alternate format in the respond_to block. Clicking a link going to \/orders, was instead taking them to \/orders.xls, which I have in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[28],"_links":{"self":[{"href":"https:\/\/unixmonkey.net\/index.php?rest_route=\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/unixmonkey.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unixmonkey.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unixmonkey.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unixmonkey.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":0,"href":"https:\/\/unixmonkey.net\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/unixmonkey.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unixmonkey.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unixmonkey.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}