Archive for the ‘Ruby on Rails’ Category

You are currently browsing the archives for the Ruby on Rails category.

Remote Viewing: Pair Programming with iChat Screen Sharing

Posted November 14th, 2008 in Development, Ruby on Rails | Permanent Link

I’ve spent most of this week doing hardcore pair programming on a new web app that we’re working on at SEO Logic. But my daughter was sick today, so I ended up working from home while my wife taught her classes at the Homeschool Coop. We didn’t let this stop us from continuing to pair program, however.

If you use iChat, you may have noticed a small double-rectangle icon at the bottom of your buddy list:

Pair programming with iChat screen sharing

So all I had to do was plug in a USB headset for audio in and out (echoes and feedback otherwise), select my programming partner from the iChat window, and click that icon to start screen sharing.

After a few seconds, he could see my desktop in real time and full size on his machine, while his own desktop floated in a minimized window. Either one of us could control my laptop, with full support for keyboard shortcuts… everything you would expect to be able to do if sitting side by side with a second keyboard and mouse.

Screen sharing in action.

Surprisingly, the one keyboard shortcut that he could not execute remotely, instead affecting his own computer, ended up being a handy one– command-shift-3, used to take the screen shot above.

I should point out that we were both on laptops with connectivity through 801.11g wireless routers, and there was absolutely no discernable lag in voice communications, keystrokes, or screen drawing.

A couple of years ago we were blown away by SubEthaEdit, which let multiple people edit the same document in real time. I remember wishing at the time that BBEdit would let you do that. Now with iChat screen sharing, that’s a reality.

Moving Back to BBEdit from TextMate

Posted November 4th, 2008 in Ruby on Rails | Permanent Link

Though it pained me at the time, last year I felt compelled to leave my favorite text editor– BBEdit– for TextMate. I had been using BBEdit for years and years as my IDE, but when I made the move to Ruby on Rails I followed the lead of other Mac-based Rails developers and adopted TextMate. Although the move was relatively painless, something just didn’t feel right.

I won’t do a feature-by-feature comparison, but I will say that while the Rails-specific features were nice, there were a lot of BBEdit niceties that I missed, or whose TextMate analogues I found lacking.

So when Bare Bones released BBEdit 9 a couple of months ago, I decided to test the waters and see if I could return to my old favorite without losing the productivity gains I got with TextMate. I’m happy to say that I haven’t opened TextMate at all since then. I initially stumbled across (and reported) a few bugs related to the handling of Ruby in the editor, but was amazed at the incredibly fast response and turnaround time for fixes.

Project Management

Besides the extended Ruby on Rails language support, probably the most important BBEdit feature from a Rails development perspective is the new Project functionality. Long-time BBEdit users will probably recognize this as an evolution of the Disk Browser feature.

Projects are basically a group of related files and folders from the file system. So in a typical Rails app, the BBEdit Project file would contain all of the files and folders in your application’s root directory.

Projects provide single-window editing capability, which is vital while working across model, view, helper, and controller files. You can slide open the Documents Drawer to see all of the docs you’ve got open, and move between them using a keyboard shortcut; I think that command-] and command-[ are the defaults.


BBEdit’s Project window…

…compared to TextMate’s interface.

This pretty much parallels TextMate functionality, with the exception that Project files and folders are not limited to a single root folder. You can also create Collections within projects, so if you have conf files related to your project (e.g. host files, vhosts, or what have you) you can maintain quick access to them from the Project window.

To create a Project in BBEdit, simply go to New -> Project, and then drag-and-drop your files and folders. You can save the Project file wherever you like– I keep all of the BBEdit Project files in my ~/Documents/projects/ folder, at the same level in the file hierarchy as my Git repositories. This keeps them easy to access but out of source control.

Scoping Multi-File Search

BBEdit has always provided fast and robust search capabilities, especially compared to the dog-slow multi-file searching in TextMate.You also now have ability to edit right from within the search results list. Nice. But take a few minutes to optimize the way you search, and you’ll be even more productive.

In the multi-file search dialog, set up a File Filter defining Rails source code as any file with one of the following line endings:

  • .rb
  • .erb
  • .rjs
  • .html
  • .rthml
  • .yaml
  • .css
  • .js
  • .haml

Then click ‘Other’ in the find dialog box and select just the folders you’re going to want to search in (most likely app/models, app/views, app/controllers, and app/helpers). Otherwise, you may find yourself with a lot of false positives as BBEdit searches through log/, lib/, and vendor/. Be sure to save your search set and name it for your project.

Clippings

Clippings make short work of Rails coding in BBEdit. Clippings are just snippets of code that can be inserted with a few key presses, and BBEdit 9 comes with two sets just for Rails development: Ruby, and Ruby in HTML. Create a keyboard shortcut for the Clippings > Insert Clipping menu item by bringing up Preferences > Menus > Clippings and selecting Insert Clipping. (I use option-command-c.)

To insert a clipping, simply invoke the clipping pallete using your shortcut, and start typing the clipping tag that you want; for example, to insert a template for a class definition, start typing “cla”, and when auto-complete shows the correct clipping, just hit enter.

Now you can tab through the placeholders (in this case, the ClassName and the interior of the class) and enter the appropriate code.

You can also create your own snippets; check the BBEdit help for instructions.

I’ve created a quick reference sheet that organizes all of the Rails-related clippings on one page, suitable for hanging on the wall near your desk:

Rails ActiveRecord Relationships Flowchart

Posted October 26th, 2008 in Ruby on Rails | Permanent Link

One of the remarkable things about Rails is how easy it is to create and manage relationships between objects. ActiveRecord provides this powerful and flexible object-relational mapping (ORM) capability.

Even though there are only a handful of methods involved, it can sometimes be a little confusing to newcomers; and even when you’ve got the big picture down, you might need help remembering the small details, like where to put the foreign key.

To that end, I created a simple flowchart that guides you through the process of setting up your ActiveRecord associations. It’s pinned to the wall next to my desk; hopefully you’ll find it a handy reference as well.

Other formats:


Creative Commons License

Rails ActiveRecord Relationship Flowchart by Corey Ehmke is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
Based on a work at www.idolhands.com.


Ruby on Rails Resources

Posted October 5th, 2008 in Ruby on Rails | Permanent Link

If you check out the left-hand sidebar, you’ll see that I’ve added something new to the site. The Ruby on Rails Resources page presents a categorized list of Rails sites, screencasts, podcasts, and discussion groups that I have personally found useful in getting to know and love Rails.

So please check it out, and use the comment form on the page to suggest any other resources that I may have missed.

Bizarre BBEdit 9 bug

Posted September 5th, 2008 in Development, Ruby on Rails | Permanent Link

After upgrading to BBEdit 9, I’ve happily left TextMate behind and returned to my favorite bare-bones IDE for Rails development. (I’m planning to share some tips on this topic this weekend.)

I just came across a very strange bug that crashes BBEdit, and thought I’d share a workaround in case someone else has this problem. The bug report has already been filed.

Operating environment:
BBEdit version 9.0 (1320) of Wed, 27 Aug 2008
Mac OS X 10.5.4 Build 9E17

To reproduce:

  • Create a new file
  • Set its type to Ruby using the menu at the bottom of the window
  • Type (not paste) the following, exactly as you see it here:

    "tag-#

BBEdit will now invoke the spinning beach ball of death, start consuming massive CPU cycles, and never recover. Note that I have text completion triggers turned OFF, so that’s probably not the problem.

The workaround for this is (and any similar string that brings this on) is open the Scratchpad window (Window -> Show Scratchpad), type your string in there, and paste it back into your Ruby file.

I should point out that a couple of minor issues aside, I’m incredibly happy with this upgrade. And given my history with Bare Bones, I expect fixes to be forthcoming quickly.