Created
November 23, 2010 18:03
-
-
Save franckverrot/712202 to your computer and use it in GitHub Desktop.
default_scope without proc on Rails 2.3.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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