Rails 3 Translation Missing Error

posted on Tuesday, February 08, 2011

In one of my projects I had to use I18n and I had a problem always seeing something like:
translation missing: ru.activerecord.errors.messages.record_invalid when there is no translation found.
I prefer to see default English translation if there is a translation missing error, why not ?
Especially in development mode.
So here is a small piece of code that you can put into config/initializers folder:

module I18n
  def self.custom_handler(exception, locale, key, options)
    case exception
    when I18n::MissingTranslationData
      I18n::Backend::Simple.new.translate(:en, key, options || {})
    else
      raise exception
    end
  end
end
I18n.exception_handler = :custom_handler
Continue reading

Rails 3 dynamic view_path

posted on Tuesday, December 14, 2010

There is an easy way to add view path dynamicly inside ActionController using prepend_view_path or append_view_path. But there is a problem because each request will start a filesystem traversal to do a pathset, we don't want to do that especially if there is a big project.

So here is an idea of how to handle that view_path insertion...

Continue reading

Rails 3 routing

posted on Friday, April 30, 2010

Lets see Rails 3 new routing interface and compare it to Rails 2 old brother

# Rails 2
ActionController::Routing::Routes.draw do |map|
  map.connect "/:controller/:action/:id"
end
# Rails 3
YourAppName::Application.routes do
  match "/:controller(/:action(/:id))(.:format)"
end

Controller and action in a single string:

# Rails 2
map.about "/about", :controller => "info", :action => "about"
# Rails 3
match "/about" => "info#about", :as => :about

How about routing to another application:

Continue reading