Forum: Ruby on Rails Why does default scope break the #new method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2bd7446a46f3e5eede1527cc9599e5af?d=identicon&s=25 David Beckwith (dbit)
on 2009-03-16 16:55
(Received via mailing list)
class Event < ActiveRecord::Base
  default_scope :conditions => "id = 1"
end

Event.new

undefined method `1=' for #<Event:0xb68ce02c>
872535e214a9e3a98889bd8d069f0294?d=identicon&s=25 "Wolas!" (Guest)
on 2009-03-16 17:08
(Received via mailing list)
class Event < ActiveRecord::Base
  default_scope :conditions => {:id = 1}
end

just a guess
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick (Guest)
on 2009-03-16 18:56
(Received via mailing list)
":id => 1" or {:id =>1}
548dde5574b950a8ac2f09cb0ee681d5?d=identicon&s=25 Andrew France (Guest)
on 2009-03-16 19:09
(Received via mailing list)
On Mar 16, 3:54 pm, David Beckwith <dbitsoluti...@gmail.com> 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-
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
Eb8d375308e3c12a470813849ca0325c?d=identicon&s=25 Rick Bradley (Guest)
on 2009-03-17 23:03
(Received via mailing list)
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)
Fd8105084dd29d1681ed581b3aaa7db0?d=identicon&s=25 Samo (Guest)
on 2009-05-16 12:25
(Received via mailing list)
Any news on this? I'm also on Rails 2.3.2. and can't find a way around
this bug.
This topic is locked and can not be replied to.