# Why does default scope break the #new method?

**URL:** <https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014>\
**Category:** Rails\
**Created:** [March 16, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014 "2009-03-16T16:55:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 16, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/1 "2009-03-16T16:55:22Z")

</div>

class Event \< ActiveRecord::Base  
default\_scope :conditions =\> “id = 1”  
end

Event.new

undefined method `1=’ for #Event:0xb68ce02c

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 16, 2009, 5:08pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/2 "2009-03-16T17:08:54Z")

</div>

class Event \< ActiveRecord::Base  
default\_scope :conditions =\> {:id = 1}  
end

just a guess

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 16, 2009, 6:56pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/3 "2009-03-16T18:56:20Z")

</div>

“:id =\> 1” or {:id =\>1}

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 17, 2009, 11:03pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/4 "2009-03-17T23:03:51Z")

</div>

Fwiw, I’m seeing similar things even on 2.3.2, with slightly different  
default\_scopes:

default\_scope :conditions =\> [“played\_on \< ?”, Time.now]

leads to:

undefined method `played\_on \< ?=’ for #Game:0x21c5e88 (when  
Game.new is called)

when I call Game.new

Best,  
Rick

(and, yes, I know Time.now isn’t going to do what I expect, just ended  
up there while trying to troubleshoot the problem)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [May 16, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/5 "2009-05-16T12:25:35Z")

</div>

Any news on this? I’m also on Rails 2.3.2. and can’t find a way around  
this bug.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 16, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/why-does-default-scope-break-the-new-method/163014/6 "2009-03-16T19:09:53Z")

</div>

On Mar 16, 3:54 pm, David B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class Event \< ActiveRecord::Base  
> default\_scope :conditions =\> “id = 1”  
> end
> 
> Event.new
> 
> undefined method `1=’ for #Event:0xb68ce02c

With regards to the other responses, your syntax is fine.  
Default\_scope with conditions has seemed a bit broken recently (http://  
[rails.lighthouseapp.com/projects/8994/tickets/2199-default\_scope-](http://rails.lighthouseapp.com/projects/8994/tickets/2199-default_scope-)  
errors-with-named\_scope) but I’ve just updated to tag v2.3.2 and your  
specific example now works fine.

Hope that helps.  
Andrew
