Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Action Controller always renders JS/JSON for XHRs

#1594
  • Make two templates for an action, one .html.erb and the other .js.erb
  • Make a get request that will be routed to that action with X-Requested-With: XMLHttpRequest.
  • You will always get the .js.erb template, even though request.format will show e.g. text/html. This behaviour is reversed by requesting action/0.html, but not by setting the Accepts: header and use_accepts_header appropriately.

This was observed on an otherwise pristine 2.2 project. On our existing project, it was rendering HTML and then wrapping it in a JSON object, but I haven't looked into that enough.

Reported by Peter Abrahamsen · December 18th, 2008 @ 12:01 AM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Peter Abrahamsen
    Peter Abrahamsen

    I've commented out action_controller/request.rb:182,183 (template_format, the elsif xhr? clause) and my life went back to normal.

    December 18th, 2008 @ 12:34 AM

  2. Pratik
    Pratik
    • State changed from new to incomplete
    • Assigned user set to josh
    • Title changed from ActionController always renders JS/JSON for XHRs to Action Controller always renders JS/JSON for XHRs

    Could you please confirm if this is still a problem ? A failing test case would be awesome - http://guides.rails.info/contrib...

    March 13th, 2009 @ 03:44 PM

  3. josh
    josh
    • Assigned user cleared.

    August 19th, 2009 @ 03:46 PM

  4. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:42 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:42 PM