Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use scope as we now assume rails 3

  • Loading branch information...
commit 08137d0c6b1bbdb0c7944843023295bcfab45f27 1 parent 21646c2
Sven Fuchs svenfuchs authored
Showing with 3 additions and 7 deletions.
  1. +2 −4 lib/globalize/active_record/act_macro.rb
  2. +1 −3 test/data/models.rb
6 lib/globalize/active_record/act_macro.rb
View
@@ -27,15 +27,13 @@ def translates(*attr_names)
:foreign_key => class_name.foreign_key,
:dependent => :delete_all
- scope_method = ::ActiveRecord::VERSION::MAJOR >= 3 ? :scope : :named_scope
-
- send(scope_method, :with_translations, lambda { |locale|
+ scope :with_translations, lambda { |locale|
conditions = required_attributes.map do |attribute|
"#{quoted_translation_table_name}.#{attribute} IS NOT NULL"
end
conditions << "#{quoted_translation_table_name}.locale = ?"
{ :include => :translations, :conditions => [conditions.join(' AND '), locale] }
- })
+ }
attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
end
4 test/data/models.rb
View
@@ -10,9 +10,7 @@ def existing_method ; end
class Post < ActiveRecord::Base
translates :subject, :content
validates_presence_of :subject
-
- scope_method = ::ActiveRecord::VERSION::MAJOR >= 3 ? :scope : :named_scope
- send(scope_method, :foobar, :conditions => { :title => "foobar" })
+ scope :foobar, :conditions => { :title => "foobar" }
end
class Blog < ActiveRecord::Base
Please sign in to comment.
Something went wrong with that request. Please try again.