DevSummit07:Power Ruby On Rails

From DevSummit
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Facilitated by Evan Henshaw-Plath, protest.net, and Josh Crawford, Brattleboro Tech Collective

This participant-driven session will allow Evan and Josh to share their Ruby experiences, and open up the floor for questions and discussion.

Session Notes

How Ruby does AJAX: really wrong. Send off request, then rails app renders it into HTML, and then jsut kind of shoves it into the slot. You can do almost everything you want to do, but it's not correct-fomr AJAX and breaks sometimes. It expects you to have Javascript, and if you have it turned off the links won't work.

Proper AJAX request: Send off request, get data structure back, parse data and then do injections into the DOM. Code is converted into HTML in the browser.

Unobtrusive Javascript -- made to rectify this. No Javascript in the HTML, so if Javascript isn't there, the HTML still works. Once you include the unobtrusive Javascript, it generates the Javascript file for you and removes the objectionable Ruby code. It's a plug-in.

AJAX is important -- it reduces response times. Rule of thumb is less than a second response time will make people think it's "immediate", and if it's more than a second it's a problem. However, it does have accessibility problems. It is also a problem if someone wants to bookmark your page.

Capistrano -- back-end and sysadmin related. It's a framework that is kind of like "Make" or "Ant". It's a build system, that is also very aware of the network. It handles ftp-type functions automatically. When you're finished coding, you hit "Deploy" and hit handles all the database functions automatically.

In rails you can "fool" the browser so that new information and applications can appear on what is actually the same page. This also can save previous states in the browser, so that the back button will return the user to previous states, instead of previous pages. Of course, the problem with this is that it's right on the edge of what scammers and spammers to in order to perform id theft, although this is for legitimate purposes.


MemCache - get keys, put data in it, and get data out. Always in memory. Ruby in rails normally sets one sessionid (cookie) and stores data on the server. By default it is stored in the filesystem, which is fine for developers, but once your traffic goes up, most filesystems don't like that. MemCache, by storing information in memory, solves this problem. On larger systems (more than one front-end web server), it also works by sharing the data in a shared memory pool between the servers. Use the Robot co-op, not the official gem.

Evan's best practices:

  • Use Unobtrusive Javascript
  • Don't use scaffolding.
  • Use post back.
  • Use the same action code for new and editing model objects, btu different ones for display.
  • Keep methods really short. Try to extract one line into a separate method, if it's got three things going on in it.
  • Use gated conditional design-pattern.
  • Use "before" filter and "verify". Verify is useful for security, smart-redirects.
  • Behavior-driven development. Sit down with end users and ask "are these english readable about how these applications function?"
  • Heckle -- a Ruby implementation of Jester-- checks that your code is robust.