I know I can set default_scope for individual active record model, but can I set one up for the whole application? thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Feb-02 14:23 UTC
Re: how to set default_scope for the whole application?
Well, I imagine you could, as long as all of your models had a key in common. I mean, there''s no practical difference between vanilla Rails and this: default_scope order(''id ASC'') But if all of your models had a :position maybe you could do this default_scope order(''position ASC'') and see what happens. I have my doubts -- everything Controller-wise inherits from ApplicationController, and what about controllers that don''t just manage one model? This sort of thing has got to end badly is my guess. Walter On Feb 1, 2011, at 10:15 PM, slava wrote:> I know I can set default_scope for individual active record model, but > can I set one up for the whole application? > > thanks > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Slava Mikerin
2011-Feb-02 19:00 UTC
Re: how to set default_scope for the whole application?
I want is to set default_scope :order => ''created_at ASC'' for all models on default. How is that done? On Wed, Feb 2, 2011 at 6:23 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Well, I imagine you could, as long as all of your models had a key in > common. I mean, there''s no practical difference between vanilla Rails and > this: > > default_scope order(''id ASC'') > > But if all of your models had a :position maybe you could do this > > default_scope order(''position ASC'') > > and see what happens. I have my doubts -- everything Controller-wise > inherits from ApplicationController, and what about controllers that don''t > just manage one model? This sort of thing has got to end badly is my guess. > > Walter > > > On Feb 1, 2011, at 10:15 PM, slava wrote: > > I know I can set default_scope for individual active record model, but >> can I set one up for the whole application? >> >> thanks >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Slava Mikerin
2011-Feb-02 19:01 UTC
Re: how to set default_scope for the whole application?
in what file do I put this or similar code? On Wed, Feb 2, 2011 at 11:00 AM, Slava Mikerin <mikerin.slava-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I want is to set > default_scope :order => ''created_at ASC'' > for all models on default. How is that done? > > > On Wed, Feb 2, 2011 at 6:23 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org>wrote: > >> Well, I imagine you could, as long as all of your models had a key in >> common. I mean, there''s no practical difference between vanilla Rails and >> this: >> >> default_scope order(''id ASC'') >> >> But if all of your models had a :position maybe you could do this >> >> default_scope order(''position ASC'') >> >> and see what happens. I have my doubts -- everything Controller-wise >> inherits from ApplicationController, and what about controllers that don''t >> just manage one model? This sort of thing has got to end badly is my guess. >> >> Walter >> >> >> On Feb 1, 2011, at 10:15 PM, slava wrote: >> >> I know I can set default_scope for individual active record model, but >>> can I set one up for the whole application? >>> >>> thanks >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 2, 2:00 pm, Slava Mikerin <mikerin.sl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want is to set > default_scope :order => ''created_at ASC'' > for all models on default. How is that done?I might be wrong but unless you don''t have IDs in your tables what you are trying to do is equivalent to leaving things as they are since the IDs are created in ascending order and retrieve in the same way (maybe I read somewhere that Postgre might be an exception), the same thing that happens with the values of created_at. That is, unless you are planning on changing the value of created_at manually after the record has already been created or the computer clock is reset or... pick your choice of "strange" stuff here. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2011 03:15, slava <mikerin.slava-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I know I can set default_scope for individual active record model, but > can I set one up for the whole application?I guess you could derive a class from ActiveRecord::Base and put the default scope in there, then derive your models from that. I have not tried it though. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > I want is to set > > default_scope :order => ''created_at ASC'' > > for all models on default. How is that done?If you want to do this no matter what I think there should be a way to do it at initialization. If you are using Rails 2.3.x you might be able to do it in ''new_rails_defaults.rb'' in folder config/ initizializers. I have not used Rails 3 yet so I don''t know where I would make the change in that version, there is a comment in ''new_rails_defaults.rb'' saying that the contents of that script will be default in Rails 3 and the script can be removed when Rails is upgraded to 3 so maybe the script will not run, but you can always try anyway. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.