Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
def search @states = Community.states if request.post? conditions = [] if params[:community][:approval_status] == "pending" conditions << "approval_status = 'pending'" end if !params[:community][:id].blank? conditions << "id = #{params[:community][:id]}" elsif !params[:community][:zip].blank? conditions << "zip = '#{params[:community][:zip]}'" else conditions << "state = '#{params[:community][:state]}'" unless params[:community][:state].blank? conditions << "city = '#{params[:community][:city]}'" unless params[:community][:city].blank? conditions << "name like '%#{params[:community][:name]}%'" unless params[:community][:name].blank? conditions << "id = '#{params[:community][:community]}'" unless params[:community][:community].blank? end if conditions.any? @communities = if !params[:community][:zip].blank? && (params[:community][:radius] rescue 0).to_i > 0 Community.find_within_radius(params[:community][:radius], params[:community][:zip], :conditions => ["approval_status = approved"]) else if params[:community][:approval_status] == "approved" conditions << "approval_status = 'approved'" end Community.paginate :per_page => 10, :page => params[:page], :conditions => conditions.join(' and ') end # display the results render(:file => "/communities/show.html.erb", :use_full_path => true, :layout => "application") else flash[:error] = "You must specify your search criteria." render :action => :search end else respond_to do |format| format.html # show.html.erb format.xml { render :xml => @communities } end end end
From the Design Piracy series on my blog: