,我發現了以下錯誤monkeypath內...如何設置會話變量從字符串
pry("serp")> session[self.to_sym] = "closed"
NameError: undefined local variable or method `session' for "serp":String
...當我嘗試從上一個猴補丁中設置會話變量字符串類。 (必要的,這樣我可以跟蹤延誤作業的作業進度,以載入我的搜索結果中,只有當他們準備好了。)
如何設置會話變量嗎?還是有更好的解決方案?
我的代碼...
/config/initializers/string.rb:
class String
def multisearch
result = PgSearch.multisearch(self)
session[self.to_sym] = "closed"
return result
end
end
/app/views/searches/show.html.haml:
- if @term.present? && session[@term.to_sym] == "open"
%h1 Search In Progress
# then show spinning wheel animation etc
- else
%h1 Search Results
= form_tag search_path, :method => :get do
= text_field_tag "term", "Search term"
= submit_tag "Search"
- unless @results.blank?
# then show the search results etc
** /應用/視圖/佈局/ application.html.haml:
!!!
%html
%head
- if @term.present? && session[@term.to_sym] == "open"
%meta{:content => "5", "http-equiv" => "refresh"}/
/app/controllers/searches_controller.rb:
class SearchesController < ApplicationController
respond_to :html
filter_access_to :all
def show
if @term = params[:term]
session[@term.to_sym] = "open"
@results = @term.delay.multisearch
# other stuff...
end
end
end
謝謝!這恐怕不行。我決定停止與OO對抗,並開始構建搜索模型來擁有所有這些東西。當我得到它的工作,我會回來發佈一個答案。但首先我必須修復一個痛苦的序列化問題:http://stackoverflow.com/questions/15671773/why-cant-i-save-an-object-with-a-serialized-attribute – 2013-03-28 00:18:41