Close and Go BackBack to Viget

Building an Environment From Scratch With Capistrano 2

Matt Swasey
Matt Swasey, Web Developer, April 30, 2008 7

I recently attended the Pragmatic Programmers Advanced Rails Studio. Overall, I thought it was great. Even though I've had personal experience in most of the topics covered, it filled in a lot of gaps in my personal knowledge. I came out of the three days feeling more well-rounded as a Rails developer. I also met some cool people.

On the topic of deployment, Chad Fowler offered that Capistrano is really just an automated remote shell. That got me thinking: if you could do anything through Capistrano that you could do on the command line, you could not only automate the deployment of the application, but the construction and configuration of the environment in which that application runs.

I rebuilt my 256 slice at Slicehost with a brand new Ubuntu Hardy 8.04 install to test this out. I wanted to see if I could automate the installing and configuring of everything it would take to run a Rails application through Apache and Passenger. It worked! What follows are the steps I took to make it happen.

Continue reading "Building an Environment From Scratch With Capistrano 2"

Right Way/Wrong Way: Closed Betas

Ben Scofield
Ben Scofield, Development Director, April 29, 2008 12

That’s right, everyone—it’s time for a thrilling episode of “Right Way/Wrong Way,” in which we see two possible solutions to a problem. One of ‘em’s good, one of ‘em’s bad, but we can all learn something from both of them!

This time: closed betas.

Continue reading "Right Way/Wrong Way: Closed Betas"

I Have a Pull Request on GitHub, Now What?

Patrick Reagan
Patrick Reagan, Development Director, April 24, 2008 0

I'm a n00b when it comes to Git, so I solicited Matt's help to get the changes in my fork up to our main GitHub account. As awesome as GitHub is, there's still no "automatically-pull-and-merge" functionality when someone wants to send you their changes (and for good reason). Here's how I made it happen:

The Scenario

I wanted to work on my constant_cache gem, so I forked the project into my own GitHub account. I made the changes I wanted, ensured that all specs were passing, committed, and then pushed the changes up to my repository. Now it was time to sync up those changes with the main repository.

Continue reading "I Have a Pull Request on GitHub, Now What?"

Maintaining Lookup Data in Your Rails Application

Patrick Reagan
Patrick Reagan, Development Director, April 22, 2008 0

Early last year, Dave Thomas gave a great talk on Metaprogramming in Ruby which he reprised last week at April's NovaRUG meeting. One of the quick examples he gave during the talk inspired me to work on an idea that began as a submission to Advanced Rails Recipes, turned into a Rails plugin, and which I just re-released as a gem. Basically, it allows you to cache the lookup data for your Rails models when your application loads.

Installation

Since we're hosting our code on RubyForge, a simple gem install will fetch the latest version:

sudo gem install constant_cache

Usage

Assuming that your application has a Status model with data that looks like this:

mysql> select * from statuses;
+----+----------+
| id | name     |
+----+----------+
|  1 | Pending  | 
|  2 | Active   | 
|  3 | Disabled | 
+----+----------+
3 rows in set (0.00 sec)

All that's needed is to include the gem in your model class and instruct it to cache its data:

require 'constant_cache'
class Status
  caches_constants
end

Status data is now available as constants on the class:

$ ./script/console 
Loading development environment (Rails 2.0.2)
>> Status.find(:all).map {|s| [s.id, s.name] }
=> [[1, "Pending"], [2, "Active"], [3, "Disabled"]]
>> Status::PENDING
=> #Status id: 1, name: "Pending"
>> Status::ACTIVE
=> #Status id: 2, name: "Active"

Since the constants point to ActiveRecord instances, the real value comes when you want to use them as part of an association:

user = User.create!(:username => 'preagan', :status => Status::PENDING)

The gem relies on a name column in your database, but can be configured to use something else as needed:

class Status
  caches_constants :key => :slug
end

Other configuration options are available, see the README file for more information.

Future Additions

Right now, the gem only handles caching data that exists in the database when the application is loaded, it isn't able to handle cases when the data changes (e.g. a record is deleted, or a name is changed). I plan to handle these cases in a future release. Feedback and patches are always welcome

Passenger: Let It Ride?

Mark Cornick
Mark Cornick, Web Developer, April 21, 2008 4

Rails application deployment has gotten a pretty bad rep. Legitimate Rails developers and blog trolls alike have bemoaned the lack of something equivalent to mod_php, which would make Rails applications "just work" when uploaded to a web server, as we got used to doing in the PHP days.

So Passenger made a big splash when it was released this month. It promises to make deployment "a breeze" and says "No Ruby on Rails-specific server configuration [will be] required!" Furthermore, the developers' own benchmarks show it being a little faster than Mongrel.

After a decade-plus in IT, I'm skeptical of hype and twice as skeptical of benchmarks. But even though I've mastered the sometimes-confusing realm of Apache and Mongrel, I'm curious to see just how easy it is to use, and just how fast.

Continue reading "Passenger: Let It Ride?"

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.

Recent Comments

Tony,

I understand and agree that the back-end shouldn’t output code (html code), and only content. The templates (aka views) should do the trick, but instead of having lot’s of if/else conditionals inside the view, you may just output the following content.

No information available

The template would loop in an array and put all the <li>’s inside the <ul>.
I don’t see anything wrong, nor...