The answer was to stop fighting Ruby's OO nature and to build a Search model that could own everything I needed to access.
/app/models/search.rb:
class Search < ActiveRecord::Base
serialize :results
def multisearch
results = PgSearch.multisearch(self.term).to_a
self.update_attributes :results => results, :status => "closed"
return results
end
end
** /app/controllers/searches_controller.rb**:
class SearchesController < ApplicationController
respond_to :html
def show
if params[:term].present?
@search = Search.find_or_create_by_term(params[:term])
if @search.status.blank?
@search.delay.multisearch
@search.status = "open"
@search.save
elsif @search.status == "closed"
@search.update_attributes :status => nil
end
end
end
end
/app/views/searches/show.html.haml:
- if @search.present? && @search.status == "open"
# progress bar etc
- else
= form_tag search_path, :method => :get do
= text_field_tag "term", "Search term"
= submit_tag "Search"
- if @search.present? && @search.status.nil?
- unless @search.results.blank?
# show the search results
/app/views/layouts/application.html.haml:
- if @search.present? && @search.status == "open"
%meta{:content => "5", "http-equiv" => "refresh"}/