Created
September 14, 2012 21:51
-
-
Save plukevdh/3725131 to your computer and use it in GitHub Desktop.
jQuery <=> rails.js <=> Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TL;DR: jQuery <=> rails.js <=> Rails is a strange beast. | |
Breakdown: | |
Rails expects a format to translate a request into a response. This could be | |
HTML, JSON, Script (js request), etc. Usually a straight GET/POST/etc. translates | |
to HTML. Ajax requests translate to a Script request. An odd thing starts happening | |
when you start playing with the request type params (or acceptance headers). Rails | |
has some behind-the-scenes defaults of how it translates requests to response formats | |
when not specified or if the specified does not exists. This gets confusing the more | |
response handlers you add. | |
The process is a bit more complicated because jQuery has its own set of acceptance/request | |
type header setters/handlers, Rails has a script that handles remote forms that does | |
some magic for parsing/handling/responding to request types, and Rails expects its | |
own formats to be matched. Somewhere in between, wires get crossed funny and I haven't | |
untangled it all yet. | |
The basic problem we had/have is TJ needed a json response. He added a format.json | |
response handler. Unknowingly, I was using the JS handler (ancient code) that was actually | |
requesting json. Rails will translate JSON requests => script requests if the controller | |
lacks an explicit JSON handler, probably because it is still an Ajax request. So when | |
TJ added the EXPLICIT JSON handler, the in-meeting registry pages suddenly had a JSON | |
response, but it was not what was expected. | |
The fix for now is that the JSON responder will now check for what kind of request we | |
are handling (registration from the new landing pages or in-meeting request). | |
The proper fix is to split all of these conditions for registering and where from into | |
something much more organized and stable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rails: Web Development That Doesn't Hurt.