The right way to do something you should never do

July 23rd, 2008 by ymendel 2 comments »

One project we’re on now involves a dashboard view that has a continually updating list of items. This seemed like a perfect place to use Juggernaut.

Like with anything else, there was the YAGNI discussion. This could happen with polling and regular AJAX, right? It turns out that not only is pushing with something like Juggernaut more lightweight than polling, it’s easier. There’s no need to contact the server and say “hey, give me everything after this” if you can get an update upon creation.

The trouble is that anything involving Juggernaut seems to smack of MVC violation. It’s obvious that updating a list of items as they come in points to an observer with an after_create callback, but using Juggernaut involves creating some JavaScript by hand or using one of the helpful render calls. So I need a controller. In a model. (Or a model-like thing.)

In accordance with my M.O., I dove into the Rails code and promptly started cursing. Rick, on the other hand, did some searching and came up with a blog post from Matt Harvey. Now, while I’m sure that works, it seemed like way too much. I came up with a different solution.


class LogObserver < ActiveRecord::Observer
  def controller
    returning ActionController::Base.new do |controller|
      controller.instance_variable_set('@template', ActionView::Base.new(ActionController::Base.view_paths))
      controller.instance_variable_set('@assigns', {})
    end
  end

  def after_create(log)
    controller.render :juggernaut do |page|
      page.insert_html :after, 'dashboard_logs_top', :partial => 'logs/log', :locals => { :log => log }
    end
  end
end

I’m not especially proud, but it’s small and it works. And it has specs.

Also, Juggernaut is pretty sweet.

All together on three

July 20th, 2008 by ymendel 6 comments »

Last week was quite an experience for the good folks of OG Consulting. We were all down in Florida working with Hashrocket on a 3-2-1 project, and they don’t mess around. Well, they do mess around a bit, but in the fun way, not that “Who cares if nothing ever gets done?” way so many of us are familiar with.

The best description we could come up with to describe the week was “a boot camp we were paid to attend”. The pace was definitely different from our usual, and we don’t pair the way they do (or “at all”, according to Obie). The former comes from the 3-2-1 concept, and as for the latter, well, we don’t have an office with 30” monitors. On top of that were the new technologies and tools we were working with: Haml, jQuery, Google Maps API, Pivotal Tracker.

Now, we were all familiar with these things and had experimented with them a bit, but nothing large-scale. It takes some doing to work on something significant using a tool you’re not comfortable with, especially when it would involve either putting client work aside or just deciding to start up a client project using it, running the risk of delivering an inferior product. And in either case, it’s not the same as being on a project with someone experienced showing you the ropes.

There were many, many great points during that week, too many to go into. Simply meeting and hanging out with that group (shout-outs to Obie, Ben, Durran, El Tigre, ReinH, Veez, Zach, tpope, et al.) was a ball. The hospitality and friendliness was almost staggering at times. And it all came down to the four of us cleanly (and with tests) getting a client a better app/site in three days than someone else could do for him in six months.

And, of course, the partying.