Skip to content
This repository
Browse code

use scope as we now assume rails 3

  • Loading branch information...
commit 08137d0c6b1bbdb0c7944843023295bcfab45f27 1 parent 21646c2
Sven Fuchs svenfuchs authored
6 lib/globalize/active_record/act_macro.rb
@@ -27,15 +27,13 @@ def translates(*attr_names)
27 27 :foreign_key => class_name.foreign_key,
28 28 :dependent => :delete_all
29 29
30   - scope_method = ::ActiveRecord::VERSION::MAJOR >= 3 ? :scope : :named_scope
31   -
32   - send(scope_method, :with_translations, lambda { |locale|
  30 + scope :with_translations, lambda { |locale|
33 31 conditions = required_attributes.map do |attribute|
34 32 "#{quoted_translation_table_name}.#{attribute} IS NOT NULL"
35 33 end
36 34 conditions << "#{quoted_translation_table_name}.locale = ?"
37 35 { :include => :translations, :conditions => [conditions.join(' AND '), locale] }
38   - })
  36 + }
39 37
40 38 attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
41 39 end
4 test/data/models.rb
@@ -10,9 +10,7 @@ def existing_method ; end
10 10 class Post < ActiveRecord::Base
11 11 translates :subject, :content
12 12 validates_presence_of :subject
13   -
14   - scope_method = ::ActiveRecord::VERSION::MAJOR >= 3 ? :scope : :named_scope
15   - send(scope_method, :foobar, :conditions => { :title => "foobar" })
  13 + scope :foobar, :conditions => { :title => "foobar" }
16 14 end
17 15
18 16 class Blog < ActiveRecord::Base

0 comments on commit 08137d0

Please sign in to comment.
Something went wrong with that request. Please try again.