Tag Archives: Ruby on Rails

Problems with Rake 0.9.0 and Ruby on Rails?

Problems Rails?

If you tried to use rake in a Ruby on Rails project in the last few days, it could happen something like this:

rake aborted!
undefined method 'task' for <Your::Application:0x00000123ddd567>;

It depends on something that happened with the 0.9.0 version of Rake and you could fix it reverting to the previous version (0.8.7).

First uninstall the 0.9.0 version (maybe you should use sudo)

$ gem uninstall rake -v=0.9.0

Then specify the forced version in your Gemfile file inside your Rails application.

# Gemfile
gem 'rake', '0.8.7'

Finally update the bundle with the new (old) version of Rake.

$ bundle update rake

As a general rule, it’s advisable to specify the version of your gems inside the Gemfile, especially in production environment.

That’s all, I hope it could be useful and save your day.

Ruby on Rails Quick Tip: passing variables to i18n localized strings

UPDATE: this tutorial has been updated on May 6th, 2011. Thanks to equivalent.

Hi all,
today I want to share a little gotcha about Ruby on Rails.

I usually embed variables inside my erb (or haml) code in my view to do things like these:

  Welcome, <%= @user.name %> to our awesome app

In order to internazionalize my application I needed to pass the username from the view to the localized string.
To do it you have to pass to the translate method an hash with your variable as value and a key to be referenced inside the locale yml file:

  <%= t("message.welcome", :username => @user.name) %>

While in the locale yaml file you have to embed the placeholder inside double curly brackets, like this {{variable}}:

    welcome: "Welcome, %{username} to our awesome app"

Bye and I hope you will find this tip useful,