let''s say i have a Category model. every time i pull the categories, i
am writing something along the lines of @categories Category.find(:all, :order
=> :position)
is there a way to put something in the model so that any time i find
categories with Category.find(:all), it will automatically sort by the
position column unless i specify otherwise? i would like to be able to
change something like that in one place instead of passing the same
parameters to it every time.
i did add something like this to the model which also works:
def self.order_by_position
find(:all, :order => :position)
end
so that i can just do Category.order_by_position but was just
wondering if there''s a better way.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@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
-~----------~----~----~----~------~----~------~--~---
> let''s say i have a Category model. every time i pull the categories, i > am writing something along the lines of @categories > Category.find(:all, :order => :position) > > is there a way to put something in the model so that any time i find > categories with Category.find(:all), it will automatically sort by the > position column unless i specify otherwise? i would like to be able to > change something like that in one place instead of passing the same > parameters to it every time. > > i did add something like this to the model which also works: > > def self.order_by_position > find(:all, :order => :position) > end > > so that i can just do Category.order_by_position but was just > wondering if there''s a better way.One of these might do it... http://agilewebdevelopment.com/plugins/search?search=scope --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---