Skip to content

Instantly share code, notes, and snippets.

@mohnish
Forked from franckverrot/hash_poser.rb
Created December 24, 2013 20:59
Show Gist options
  • Save mohnish/8117753 to your computer and use it in GitHub Desktop.
Save mohnish/8117753 to your computer and use it in GitHub Desktop.
# In the model
class Foo < ActiveRecord::Base
default_scope Hash.new {|hash, key| key == :conditions ? {:baz => I18n.locale.to_s } : nil }
named_scope :bar, lambda { { :conditions => { :bar => 1..10 } } }
end
# In action
ree-1.8.7-2010.02 > I18n.locale = 'fr'
=> "fr"
ree-1.8.7-2010.02 > Foo.bar
Foo Load (0.2ms) SELECT * FROM "foos" WHERE (("foos"."baz" = 'fr' AND "foos"."bar" BETWEEN 1 AND 10))
=> []
ree-1.8.7-2010.02 > I18n.locale = 'en'
=> "en"
ree-1.8.7-2010.02 > Foo.bar
Foo Load (0.3ms) SELECT * FROM "foos" WHERE (("foos"."baz" = 'en' AND "foos"."bar" BETWEEN 1 AND 10))
=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment