Close and Go BackBack to Viget

Tips and Tricks

From TextMate to ExpressionEngine

Patrick Reagan
Patrick Reagan, Development Director, May 01, 2008 1

Between writing code, documentation, and blog posts, I spend a lot of my time working in TextMate. It's an efficient text editor, but it becomes a bit of a headache when it's time to work on a new blog post. The real problem is my process:

  1. Open TextMate and start collecting my thoughts for a post in some cohesive fashion (optional)
  2. Finalize most of the content and basic formatting
  3. Copy the content into ExpressionEngine, tweak the formatting, add hyperlinks
  4. Preview the post and publish to the site

The reason for all this masochism is my dislike for editing content in a web-based form, WYSIWYG or otherwise. I love my editor enough that I'm willing to jump through some hoops in order to use it for the bulk of my editing work. But, there's a better way to do all this.

Continue reading "From TextMate to ExpressionEngine"

Building an Environment From Scratch With Capistrano 2

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

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, Senior Developer, April 29, 2008 2

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

A Development Community for Viget Labs and Beyond

Every team member here at Viget Labs strives to be an innovator. We members of the development team are no different - that's why we're constantly engaging in community discussions and exploring the unknown that is the next generation of open-source web applications.

Viget Is Hiring!

Viget has job openings for Ruby Developers, Interns, and Front-End Developers. Learn More »

Upcoming Events

RailsConf - May 29 to June 1
Senior Developer Ben Scofield is presenting "Advanced RESTful Rails" at RailsConf

O’Reilly’s Open Source Convention - July 21 - 25
Clinton R. Nixon, our other Senior Developer, will be speaking on "Extending Rails: Understanding and Building Plugins."

Recent Comments

I might be missing something but couldn’t a clever person spoof the cookie?