The emacs-rails package turns emacs into a Ruby on Rails IDE. To put it simply, I love the package. It gets me excited to see this much active development for an emacs mode. The emacs wiki has a laundry list of the functionality that the mode provides. I don’t think a single blog post can do the functionality justice, so I just want to hightlight a few of the features below (and expand on other features in later posts).
Context Sensitive Switching Between Rails Buffers
The rails framework espouses convention over configuration, therefore you can typically make assumptions that a method named edit in your controller is going to display a view that can be found under app/views/<controller name>/edit.rhtml. Additionally, due to the frameworks conventions there are a number of other files that are generally associated with a specific controller or model.
M-Shift-up will take you directly to the primary file that is associated with the code location at point.
M-Shift-down provides a list of other potential file options from which you can choose. For example, the screenshot below shows the results of pressing
M-Shift-down when point is in the
show method of the
This functionality is actually derived from the
snippet.el package that provides another take on templating in emacs that closely mimics the templating functionality that is provided in TextMate. In the case of emacs-rails mode, these templates are tied to abbreviations. So if I type
tcl and then tab while in a migration file, then a new line will be added to the table creation and my point will be placed in the area of the title of the column. When I am done updating the column name I can tab and I will be able to enter the type of column. I tab once again an I am out of the snippet editing mode. I think the rails-mode snippet integration is nicely done.
Invocation of Rake with Task Name Completion
C-c C-c r will prompt you in the minibuffer for the rake task that you want to run. Output of the rake task is then shown in a separate
C-c / will toggle the showing or hiding of the output buffer. Rake tasks specific to testing are actually invoked via a separate command,
C-c C-c t.
For users that like to use the mouse and menus, all of the commands listed above can be accessed from the menu. I would also recommend taking a look at the two screencasts (here and here) that show emacs-rails mode in use, although there have been a number of changes to the package since the screencasts were made.