i18n and Rails Engines
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:
In environment.rb, you add
config.i18n.load_path += Dir[Rails.root.join('vendor',
'plugins', 'your_plugin', 'config', 'locales',
'*.{rb,yml}')]
If you prefer to read the Railscast: ASCIIcasts - 149: Rails Engines
Generating a timestamp string in Ruby
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:
Time.now.utc.iso8601.gsub('-', '').gsub(':', '')
Very handy if you need a timestamp in a file you’re writing.
Moved!
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 :)

From now on, you can find us at UBCA for custom software and web application development, iPhone development, Ruby and Rails contracting, or just to drink a coffee.
Roleify, a Rails authorization plugin
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
Example
The initializer
Roleify::Role.configure("role_a", "role_b") do
{
:role_a => { :dashboard_issues => :all },
:role_b => { :issues => "index" }
}
end
So, role_a refers to a Dashboard::IssuesController and role_b refers to an IssuesController.
The helper
module ApplicationHelper
include Roleify::RoleifyableHelper
end
The view
<% allowed?(Roleify::Role::ROLE_A) do %>
// whatever you want for role_a eyes only
<% end %>
More info on GitHub.
Rails `try`
try is one of those small new additions in the Rails 2.3 release. Luckily I found out about it via a Railscast
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 nil.
Don’t overuse this.
- Page 6 of 7
- Newest articles
- Newer articles
- Oldest articles
- Older articles
