Close and Go BackBack to Viget

Fast, Cheap, and Good: My Rails Rumble Experience

Patrick Reagan
Patrick Reagan, Development Director, October 24, 2008 4

There was a palpable excitement in the air when I arrived at the office yesterday – voting for the Rails Rumble competition had started and 2 of the Viget teams at HQ were tracking progress as our applications bounced around at the top of the leaderboard. Ben posted the list of the competing Viget teams and the the lessons learned, so I thought I'd expand on some of lessons we learned as a team while building the Qflip application:

Continue reading "Fast, Cheap, and Good: My Rails Rumble Experience"

Creating Resourceful Plugins

Ben Scofield
Ben Scofield, Development Director, September 30, 2008 6

It's been some time since we originally proposed the idea of resourceful plugins—a solution to the persistent problem of integrating distinct Rails applications. Over the past year, we've worked on refining the approach (in the context of our two main resourceful projects, Sandstone and Bloget), and in the course of preparing for the tutorial I gave at Railsconf Europe, we've been able to formalize (somewhat) the process of creating resourceful plugins.

Extraction

Like most good, reusable code, the best resourceful plugins are extracted from an existing app, not created ex nihilo. I generally recommend creating a new plugin only after you've built the same functionality into an application at least twice—that way, you've worked through the same problems at least two times, and should be able to create a much better solution than you'd have been able to at the start.

Once you've built the functionality into an application, the extraction process isn't that complicated. You start with the Rails plugin generator (in the examples that follow, I'll use the Bagpipes plugin):

Continue reading "Creating Resourceful Plugins"

Scala: The Adventure Begins!

Clinton R. Nixon
Clinton R. Nixon, Senior Developer, September 24, 2008 4

I’ve been enthusiastic about the Scala programming language for a few months now, and this week’s been very exciting for the Scala community. A new Scala book from the Pragmatic Programmers was announced today, and Alex Payne from Twitter gave a presentation at C4 that strongly indicates Twitter’s writing part of their platform in Scala. Given this week’s news, I thought I’d explain why I’m using Scala, and what that means for the Lab.

Continue reading "Scala: The Adventure Begins!"

Protip: TimeWithZone, All The Time

David Eisinger
David Eisinger, Web Developer, September 10, 2008 0

If you’ve ever tried to retrieve a list of ActiveRecord objects based on their timestamps, you’ve probably been bitten by the quirky time support in Rails:

>> Goal.create(:description => "Run a mile")
=> #<Goal id: 1, description: "Run a mile",
     created_at: "2008-09-09 19:32:57",
     updated_at: "2008-09-09 19:32:57">
>> Goal.find(:all, :conditions => ['created_at < ?',
     Time.now])
=> []

Huh? Checking the logs, we see that the two commands above correspond to the following queries:

INSERT INTO "goals" ("updated_at", "description",
  "created_at") VALUES('2008-09-09 19:32:57',
  'Run a mile', '2008-09-09 19:32:57')
SELECT * FROM "goals" WHERE created_at < '2008-09-09 15:33:17'

Rails stores created_at relative to Coordinated Universal Time, while Time.now is based on the system clock, running four hours behind. The solution? ActiveSupport’s TimeWithZone:

>> Goal.find(:all, :conditions => ['created_at < ?',
     Time.zone.now])
=> [#<Goal id: 1, description: "Run a mile",
     created_at: "2008-09-09 19:32:57",
     updated_at: "2008-09-09 19:32:57">]

Rule of thumb: always use TimeWithZone in your Rails projects. Date, Time and DateTime simply don’t play well with ActiveRecord. Instantiate it with Time.zone.now and Time.zone.local. To discard the time element, use beginning_of_day.

BONUS TIP

Since it’s a subclass of Time, interpolating a range of TimeWithZone objects fills in every second between the two times — not so useful if you need a date for every day in a month:

>> t = Time.zone.now
=> Tue, 09 Sep 2008 14:26:45 EDT -04:00
>> (t..(t + 1.month)).to_a.size
[9 minutes later]
=> 2592001

Fortunately, the desired behavior is just a monkeypatch away:

class ActiveSupport::TimeWithZone
  def succ
    self + 1.day
  end
end

>> (t..(t + 1.month)).to_a.size
=> 31

For more information about time zones in Rails, Geoff Buesing and Ryan Daigle have good, up-to-date posts.

Railsconf Europe Wrapup

Ben Scofield
Ben Scofield, Development Director, September 08, 2008 1

Finally, back in the office! I spent the last week in Berlin for Railsconf Europe, and though the travel can be painful at times, the conference more than made up for it. A few highlights:

  • Bratwurst on Rails - just like last year, the Berlin Ruby user group grilled thousands of brats for any attendees who happened to be in town Monday night. Great food and conversation.
  • The keynotes - from the Tuesday night panel (with DHH, Jeremy Kemper, and Koz), to DHH's and Jeremy's Wednesday keynotes, to the symposimi/ium on Thursday morning, the plenary sessions were uniformly excellent. DHH on legacy software as product of developer growth (not as a result of code rot), and Jeremy on performance stand out in particular.
  • The content - I went to a number of sessions that had outstanding content, foremost among them Sven Fuchs' on internationalization.
  • The attendees - like every conference, the best part is always the other attendees. I met a number of smart, passionate people in Berlin, and I'm excited both to keep up with them and see what they (and others) will do with the burst of inspiration that conferences like this are famous for.

Continue reading "Railsconf Europe Wrapup"

We're the Developers

at Viget Labs. We write about web development trends, tips, best practices, industry events, and our projects — all with an emphasis on Ruby on Rails.

Upcoming Events

Twin Tech III - 6 PM, January 22 - 22, 9 PM

Refresh the Triangle - 6:30 PM, January 22

Recent Comments

nice trick. Thanks.