What's going on?


Welcome to the personal blog and portfolio of Andrew Yates, Cyprus based English Software Engineer and Graphic Designer. The site is new at the moment but I'll try and keep it updated with the latest of my work and side projects... and no doubt the odd insane rant.

Adding default interpolations into I18n

By ayates.

Heres a quick and dirty monkeypatch for adding default Interpolations into I18n (v0.6.1).

module I18n
  class << self
    attr_accessor :default_interpolations

    def interpolate_hash_with_default_interpolations(string, values)
      values ||= {}
      values = (default_interpolations || {}).merge(values)

      interpolate_hash_without_default_interpolations(string, values)

    alias_method_chain :interpolate_hash, :default_interpolations


In my case I'm adding the defaults in using a before filter, allowing me to set a customer's currency e.g.

def set_default_interpolations
  I18n.default_interpolations = { currency: current_currency.symbol }

Splitting Rails routes into multiple files

By ayates.

I was just asked how you would split your Rails routes file into multiple files for instance in the case of having an application frontend and a set of routes serving your application's API.

Now, I have a number of applications which work this way and utilize routing constraints to determine which routes should be used but splitting them into more manageable individual files is a nice idea so, my first thought...