Skip to content

Instantly share code, notes, and snippets.

@sauberia
sauberia / active_record_gem.rb
Created February 15, 2016 21:18
Arel union on active record relations results in unbound value in Rais 4.2.5.1 and 5.0.0.beta2
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@sauberia
sauberia / gist:1434138
Created December 5, 2011 16:17
Call localised path method
module ApplicationHelper
def method_missing(meth, *args, &blk)
if (match = meth.to_s.match(/(.+)_path$/)).present?
meth = "#{I18n.locale}_#{meth}"
raise NoMethodError, meth unless respond_to?(meth)
send(meth, *args)
else
super
end
@sauberia
sauberia / gist:1434132
Created December 5, 2011 16:15
Example named routes locales
en:
named_routes:
article: '/news/:y/:m/:d/:article_slug(/:country_slug)(/:page)'
articles: '/news(/:country_slug)(/:page)'
country_services: '/products-and-services'
country_service: '/products-and-services/:service_slug'
fr:
named_routes:
article: '/nouvelles/:y/:m/:d/:article_slug(/:country_slug)(/:page)'
@sauberia
sauberia / gist:1434111
Created December 5, 2011 16:11
Manually creating localised routes
Example::Application.routes.draw do
REGEX_ID = /[1-9]\d*/
REGEX_COUNTRY_SLUG = /[a-zà-ÿ\-]+/
REGEX_SLUG = /[a-zà-ÿ\d\-]+/
REGEX_LOCALE = /#{I18n.available_locales.join('|')}/
def t_route name, locale
I18n.t("named_routes.#{name}", :locale => locale)