Using Erubis in Rails

Posted by mig on May 07, 2008

Swapping out ERB for Erubis in a rails application is dead easy:

Install the gem:

  gem i erubis

Require it:

  # config/environment.rb
  require 'erubis/helpers/rails_helper'

Preprocessing is awesome:

  # config/environment.rb
  require 'erubis/helpers/rails_helper'
  Erubis::Helpers::RailsHelper.preprocessing = true

With that, you can use [%= %] inside your views instead of <%= %>. So doing this…

  [%= link_to "New Post", new_article_path %]

…will process the link_to when the template is loaded. However, when it comes time to render, what is being rendered is something more like this:

  <a href="/articles/new">New Post</a>

Which loads a lot faster than the ruby.

You can also preprocess enumerable statements, this is especially useful for something like this:

  [% Category.find(:all).each do |c| %]
    <li>[%= link_to c.name, category_path(c) %]</li>
  [% end %]

Very intense.

Follow Rails Patches

Posted by mig on April 28, 2008

Now that the Rails team has moved to using Lighthouse for bug, feature, and patch tracking, it’s a lot easier (and more fun) to track the patches coming in.

Just point your rss reader to: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/events.atom and watch the action! I know that ton’s of people followed development when they were using Trac, it just wasn’t as nice.

Gedit Rails Development Pack 2

Posted by mig on March 03, 2008

I’ve put together a couple of Gedit plugins and snippets that will help your developing rails projects in Gnome.

Download gedit-rails at github.

This package includes a script that will register ERB templates and YAML files with gtksourceview. That means that you will get some nice syntax highlighting! Enjoy!