Advertisement
Guest User

Untitled

a guest
Aug 21st, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.14 KB | None | 0 0
  1. class CdbController < ApplicationController
  2.   def index
  3.     if (params[:search_string].blank?)
  4.       @contacts = Contact.paginate :per_page => 5, :page => 1, :order => "last_change DESC"
  5.       @companies = Company.paginate :per_page => 5, :page => 1, :order => "last_change DESC"
  6.     else
  7.       @search_string = params[:search_string]
  8.       if (params[:full_text].to_i == 1)
  9.         contact_conditions = Contact.conditions_by_like(@search_string)
  10.         company_conditions = Company.conditions_by_like(@search_string)
  11.       else
  12.         contact_conditions = ["first_name like ? OR last_name like ?","%"+@search_string+"%","%"+@search_string+"%"]
  13.         company_conditions = ["name like ? OR short like ?","%"+@search_string+"%","%"+@search_string+"%"]
  14.       end
  15.       @contacts = Contact.find :all,:conditions => contact_conditions, :order => "last_name"
  16.       @companies = Company.find :all,:conditions => company_conditions, :order => "name"
  17.     end
  18. #    @context = find_context
  19.   end
  20.  
  21.   private
  22.  
  23.   def find_context
  24.     unless session[:context]
  25.       session[:context] = Context.new
  26.     end
  27.     session[:context]
  28.   end
  29.  
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement