Älphä Blüë wrote:
> Okay here's what I did and yes, it's a lot shorter (thanks!):
> 
>   named_scope :compiled_this_week, lambda { { :conditions => 
> ['compiled_on > ? and compiled_on < ?', Time.now.beginning_of_week, 
> Time.now.end_of_week] } }

Why not use BETWEEN in your SQL fragment?

> 
>   def self.do_sort(sort_by, search, page)
>     (sort_by == "all") ? numpages = 120 : numpages = 20
>     compiled_this_week.paginate( :conditions => ['name like ?', 
> "%#{search}%"], :order => 'rank', :per_page => numpages, :page => page )
>   end

Here's my suggestion.  Note that this takes care of the improper naming 
of the method and variables (do_sort? why?), the illogical order of 
arguments (put the optional ones last!), and the use of strings where 
symbols (or perhaps booleans) would be more appropriate.

def self.list(name, page, fetch = nil)
  per_page = (fetch == :all) ? 120 : 20
  compiled_this_week.paginate :conditions => ['name like ?', 
"%#{name}%"], :order => 'rank', :per_page => per_page, :page => page
end

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to