I have code like this
def self.find(*args)
if @@filter
with_scope :find => {:conditions => @@filter } do
super
end
else
super
end
end
def self.paginate(*args)
if @@filter
with_scope :find => {:conditions => @@filter } do
super
end
else
super
end
end
def self.related_tag_counts(*args)
if @@filter
with_scope :find => {:conditions => @@filter } do
super
end
else
super
end
end
def self.tag_counts(*args)
if @@filter
with_scope :find => {:conditions => @@filter } do
super
end
else
super
end
end
as you can see, I''m wrapping some methods with a with_scope when
@@filtter is set. This is kind of ugly. How can I DRY this code?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hello,
def self.find(*args)
find @@filter ? {}.merge(:conditions => @@filter) : {}
super
end
Something like that is what I would do.
rubynuby wrote:> I have code like this
>
>
> def self.find(*args)
> if @@filter
> with_scope :find => {:conditions => @@filter } do
> super
> end
> else
> super
> end
> end
>
> def self.paginate(*args)
> if @@filter
> with_scope :find => {:conditions => @@filter } do
> super
> end
> else
> super
> end
> end
>
> def self.related_tag_counts(*args)
> if @@filter
> with_scope :find => {:conditions => @@filter } do
> super
> end
> else
> super
> end
> end
>
> def self.tag_counts(*args)
> if @@filter
> with_scope :find => {:conditions => @@filter } do
> super
> end
> else
> super
> end
> end
>
> as you can see, I''m wrapping some methods with a with_scope when
> @@filtter is set. This is kind of ugly. How can I DRY this code?
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
thanks, but that code causes a stack overflow. I think it''s an infinite recursion. I''m not sure how it works 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-/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 -~----------~----~----~----~------~----~------~--~---