Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ZenCocoon/814142 to your computer and use it in GitHub Desktop.
Save ZenCocoon/814142 to your computer and use it in GitHub Desktop.
scope issue under Rails 3.0.3 after upgrade from 2.3.10
#
# FIXED: Was due to a validates_inclusion_of having :within instead of :in
#
# Weird issue after upgrading from Rails 2.3.10 to Rails 3.0.3
# The scope doesn't work. It works with a new sample app but
# NOT from the upgraded one.
#
# Models
class User < ActiveRecord::Base
has_many :messages
end
class Message < ActiveRecord::Base
belongs_to :user
scope :visible, where(:visible => true)
end
# In console
>> user = User.first
=> #<User id:...>
>> user.messages
=> [#<Message id:..>, #<Message id:...>]
>> user.messages.where(:visible => true)
=> []
>> user.messages.visible
NoMethodError: undefined method `visible' for #<Class:0x1053f48e0>
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/associations/association_collection.rb:443:in `send'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/associations/association_collection.rb:443:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1121:in `with_scope'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/associations/association_proxy.rb:203:in `send'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/associations/association_proxy.rb:203:in `with_scope'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/associations/association_collection.rb:439:in `method_missing'
from (irb):13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment