MarkUsProject/Markus — pull request #933 by ioev (2012-11-23 01:52:38+00:00)
Title: Issue 475 -- Replace Prototype Legacy with new code

Issue:
There was still a bit of code relying on the prototype_legacy_helper gem, which has not been supported for a long time now. We have to removed this code, and replace it with Rails 3 conventions.

Fix:
I did a lot of research before I started this, because I wanted this fix to be as modern as possible for what is currently being done in Rails 3. For a few changes, it was easy, because it involved changing the function call name, and adding :remote => true to take advantage of Rails 3 built in UJS calls. For the "observe_field" calls, it was a little more complicated. There doesn't exist any real built in method for this in Rails 3 with prototype right now (though there appears to be better support if we were using jQuery) so the solution I finally decided on was to just write handwritten javascript and ajax calls. In Rails 3, there seems to be a big push towards writing your own javascript and there's better support for including/managing js code, so this shouldn't be too much trouble. As well, it should be quite a bit more efficient as there is much less js code floating around overall, as I could use selectors and loops to pages that had many instances of observe_field.

While fixing this, I also tried to clean up any js that wasn't in the

tag (by putting it there), and removing any duplicate js includes that I came across.

Also, the prototype_legacy_helper has been removed from the Gemfile.

Tests:
All of the unit/functional tests save the 3 that were failing in master are passing, and after removing the prototype_legacy_helper I manually tested any of the pages that had code changed, to make sure the functionality still works. I couldn't find any specific problems, and the js generated should be basically the same as what the helper was generating, but a bit more organized.

I should also note that in the hand written js, I am grabbing the AUTH_TOKEN and sending that along with the requests, which might not be necessary anymore, as it's also included by the browser through a meta tag. I left them in though as it might be required for older browsers, and I'm not sure what the schools would be using. Just thought this was worth mentioning because in newer rails versions, it doesn't seem like you're expected to ever send this by hand.