One of the hardest things I find myself doing (being a newbie to rails)
is getting back into the long frame of mind with other languages I
program in.

Take for instance this method:

def self.do_sort(sort_by, search, page)
    start_date = Time.now.beginning_of_week
    end_date = Time.now.end_of_week
    if (sort_by != "all") then
      paginate :per_page => 20, :page => page,
        :conditions => ['compiled_on > ? and compiled_on < ?',
start_date, end_date],
        :conditions => ['name like ?', "%#{search}%"],
        :order => 'rank'
    else
      paginate :per_page => 120, :page => page,
        :conditions => ['compiled_on > ? and compiled_on < ?',
start_date, end_date],
        :conditions => ['name like ?', "%#{search}%"],
        :order => 'rank'
    end
  end

It works fine but again, it doesn't appear DRY because the conditions
match for both sides of the equation.  The only things I'm changing are
the page parameters.

How do I make this dry and pretty?
-- 
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