Resources For Rails Development in Vim

While most programming languages seem to take steps toward big, full-featured graphical IDEs, Rails development seems to have gone the reverse: back to the command line, command line editors, and minimalist interfaces. Today, I’d like to share with you several resources that I’ve used to streamline my development process.

TextMate (€39) — Considered the definitive text editor for OS X, TextMate is a worthwhile purchase for any developer using any language. It’s extensible, powerful, and, Rails-specifically, allows for easy navigation between your MVC layers with easy hotkeys. If you code on OS X, you owe it to yourself to buy this.

The Playbook (free/$15/$50) — If you’re looking for tips on how to start a web design firm, set up your development environment, do proper project management, and more, consider picking up a copy of The Playbook, an eBook written by the geniuses at ThoughtBot. ThoughtBot is known for several of their Ruby gems that have been released into the public domain, including high_voltage, clearance, suspenders, and more. They are also known for some of their hugely popular applications, including Airbrake and Trajectory. They offer a few free snippets, a single user license, and a group license.

Rails.vim (free) — While Vim is an amazing editor on its own, it thankfully allows for plugins to be written to extend the functionality. Written by Tim Pope (Twitter/GitHub), Rails.vim is an amazing plugin that adds a whole host of commands to the editor, allowing for more fluid Rails development. Best of all, it’s free, open source, and readily available on our favourite source control repository, GitHub.

Vim for Rails Developers ($15/$50) — Vim is considered one of the most powerful text editors out there, and it’s available on virtually every platform. That being said, it’s a dauntingly steep learning curve (although I wrote a guide on getting started with it), and every bit of help you can get is worth it. This 34 minute video gives you the rundown of using rails.vim along with your Vim install. As with The Playbook, a single user and group license is available.

RailsCasts (free/$9 per mo) — Probably the go-to for most Rails podcasts, Ryan Bates (Twitter/GitHub) has been churning out 2 podcasts about Ruby on Rails for years now. He explains topics clearly, pushes the limits of what gems can do, and always offers comparisons between similar gems. Most of his content is free, but Pro users ($9/month) get access to Pro episodes which cover more content and new gems.

Rails 3 Generators: Adding Migration Templates

I’ve been working on some really cool projects using Ruby on Rails recently, but I found myself duplicating code across them. Obviously, that doesn’t make sense to me, even when the code bases are different, so I decided to start extracting some of the logic into Ruby’s awesome gem format. Rails 3 has awesome gem handling, if I’ve found uses for some of these pieces of functionality across multiple projects, then others may as well.

The first gem I’m working on stems from this post from a couple years ago where I demonstrated how to do dynamically-named routes using semi-static pages. This approach was different than ThoughtBot’s high_voltage gem because it stored the page content in the database rather than as files in the database deployment. I have an issue with that implementation because I’m a firm believer that you shouldn’t have to deploy a new revision of your software just to update a bit of content; it should be controllable from the user interface as part of our regular CRUD routine.

My first struggle with the creation of the gem was writing a template for the migration. I had some trouble with these two errors coming up:

  • 1
    undefined method `migration_template' for #<Semisonic::InstallGenerator:0x000000040899c8> (NoMethodError)
  • 1
    `next_migration_number': NotImplementedError (NotImplementedError)

Maybe my Google skills have been slipping, but I had trouble finding a ‘fix’ for these. So, here’s how to fix the above errors if you ever get them:

  • If you get the first error (undefined method ‘migration_template’), you’re missing an include in your class. Add “include Rails::Generators::Migration” on the first line of your generator class, and you’re good to go!
  • If you get the second error (‘next_migration_number’ not implemented), you’ll need to implement the method ‘next_migration_number’. The following code snippet should work just fine for it:
    def self.next_migration_number(path)
      unless @prev_migration_nr
        @prev_migration_nr ="%Y%m%d%H%M%S").to_i
        @prev_migration_nr += 1

Hopefully those two fixes help somebody else out.

From Paperwork to Web 2.0: UMSwing’s New Membership System

Nowadays, my life has a good amount of its time consumed with either work or swing dancing. I work every weekday, and four nights every week I’m dancing. Being the nerd that I am, I always look for opportunities to intertwine my hobbies, despite them being complete opposites. Being on the executive committee helps a lot with that, since I take the position of Web Administrator and Graphics Designer with UMSwing.

On the way home from an event a couple weeks ago, I was talking with a friend about the hassle of all the paperwork we have to go through every time we have a lesson; we need to fill out transaction logs for each payment, keep track of every person’s attendance for each class, and also mark it on their membership form that they attended and paid for that class. A single person dropping in to that class requires writing on three sheets of paper. When you’re trying to run everybody through quickly, that starts becoming an issue.

This friend, being the kind of person that seems to regurgitate good ideas on demand, suggested to me, “Brian, you’re a developer. Just write a program to do it for you. You’re learning Ruby and Rails, so you can do a web-based backend and a GUI frontend. Problem solved!”. Thus, I sat down and started planning. Rails seems to be yet another one of those languages that lacks any decent documentation or tutorials. If you plan on learning it, pick up “Agile Web Development With Rails“. It is by far the best development book I have ever read. If it’s any sort of selling point, one of the authors created the Rails framework; if he doesn’t know how to use the framework, nobody does.

As a method for potentially helping me brainstorm, I’ve decided to spill out some of my ideas and goals here. I’m only going to discuss a few ideas here; while I would normally immediately distribute this idea into the public domain, I’ve decided to keep this one closed source. If you have any suggestions or ideas, let me know and I will give you credit. Better yet, if you’re interested in this software, get in touch and we can discuss it.

Goals for Dance Site

  • Members: Keep track of all members, regardless of how long ago they joined. Eliminate the need to fill out a new membership form every semester. Each member should be assigned a member number, which can be put on a barcode. Keep track of personal information, interests, and attendance. Gather statistics/metrics from attendance vs. month/day/semester, etc.
  • Memberships: Handle multiple membership types, including drop-in. Integrate with finances to determine when a user has paid for their membership through drop-ins. Support for online payments through Paypal (ie. Mastercard, Visa, eCheck, etc.)
  • Finances: handle per-lesson incomes. Support for multiple lessons per day. Keep track of what is taught during that lesson. Provide unlockable content for each lesson; attendance to that lesson unlocks the content for that member; refresher videos, class notes, etc. Support for discounted membership dates/times.
  • Graduated system: attendance of X number of events allows you to attend higher level classes. Ability to override by administrator.
  • Mailing List: Separate old members by current members, allowing for class updates to be sent to current members, while global events to be sent to all. Ability to unsubscribe.