Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created August 15, 2011 15:53
Show Gist options
  • Save bjhaid/1147049 to your computer and use it in GitHub Desktop.
Save bjhaid/1147049 to your computer and use it in GitHub Desktop.
class AjaxsearchController < ApplicationController
require 'stalker'
def new
begin
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b><a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
# @search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}'"}).collect{ |user| { :first_name => user.first_name :id => user.account_id, :name => user.account_name }}
rescue
@search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}%'"}).collect{ |user| "<tr><td><b><a href='http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record="+"#{user.id}" + "'>" + "#{user.account_name}"+"</b></td>" + "</a><td>Email address: <b>" + "#{user.email1}"+"</b>&nbsp;<a href=" + 'http://10.10.5.104:8080/wakanow/index.php?module=Contacts&action=DetailView&record=' + "#{user.id}" + "><img border=0 src='jquery/images/contacts.gif' title=" + "#{user.account_name}" + "/></a></tr>" }
# @search = Sugar.find(:all, :conditions => {:first_name => "LIKE '%#{params[:name]}'"}).collect{ |user| { :first_name => user.first_name :id => user.account_id, :name => user.account_name }}
end
#@search = Ajaxsearch.fetch(params[:name])
@ajaxsearches = Ajaxsearch.create({:name => params[:name], :extenno => params[:extenno]})
if @ajaxsearches.update_attributes(params[:ajaxsearch])
#s = Stalker.enqueue('search', :id => @search.id)
faye = Faye::Client.new('http://10.10.5.96:9292/faye')
msge = JSON.dump('channel' => "/ajaxsearches", 'data' => {'exten_no' => "#{@ajaxsearches.extenno}", 'resarray' => "#{@search* ","}"})
uri = URI.parse('http://0.0.0.0:9292/faye')
Net::HTTP.post_form(uri, :message => msge)
end
end
def create
@ajaxsearches = Ajaxsearch.new(params[:incoming])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment