Rails Engines, what are they? What do they do? But most importantly: how do they do it?
Rails 2.3 brings us much of the same functionality as the Rails Engines plugin. Learn how to embed one application into another in this episode.
Engines allow us to use one application in another in the form of a plugin. As the screencast shows, you can integrate the
app folder of a Rails application in the plugin of another one. All models, controllers and views are available. If you still need custom functionality, you can add them in your applications ‘own’
app folder by redefining the model, controller or view. The same goes for routes; if you have
routes.rb in your plugin dir, it is loaded as well.
And i18n, how about that? You would expect
config/locals/*.yml to work just as nicely as the
app dir and
routes.rb. But it doesn’t.
Luckily, it’s not that hard to solve:
environment.rb, you add
In the hope that the Google Gods will help me next time I need this :-)
An easy way to generate a human-readable timestamp string, following the ISO 8601 standard, is:
Very handy if you need a timestamp in a file you’re writing.
We‘ve moved today. Closer to our homes, and that was necessary. You can now better reach us, and that was even more necessary. The fact that the office is nice, is a great plus :)
Today I’ve pushed a few updates to the Roleify rails plugin.
The changes are
- you can now use ‘namespaced’ controllers
- I added a helper method to hide/show blocks for a specified role
role_a refers to a
role_b refers to an
More info on GitHub.
What is it?
Invokes the method identified by the symbol method, passing it any arguments and/or the block specified, just like the regular Ruby Object#send does. Unlike that method however, a NoMethodError exception will not be raised and nil will be returned instead, if the receiving object is a nil object or NilClass.
What did you just say?
The code above normally throws an exception if
someobject is nil. By using
try it just returns
Don’t overuse this.
Sign up for our newsletter
Who’s got the mic?
Architecture & Design
Koen Van Der Auwera
Bob Van Landuyt
Nathan de Witte