Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
class MyModel def self.find_entries(params) fields = [:prefix, :two_letter, :three_letter] conditions = fields.inject([[]]) do |where, field| unless params[field].blank? where.first << "#{field} LIKE ?" where << "%#{params[field]}%" end where end if conditions.first.empty? [] else conditions[0] = conditions.first.join(" AND ") paginate :conditions => conditions, :page => params[:page], :per_page => 10 end end end
This paste will be private.
From the Design Piracy series on my blog: