2012-02-23 43 views
0

我想在視圖中執行兩個輔助函數,第一個返回第一個。我知道下面的功能正常返回所需的哈希:流中的多個JSON對象

%p = helper_method0 params[:some_string] #does a request on a third party site which responds with json data wich is then parsed by yajl and the hash is returned to view 

然而,當我打電話以下幾點:

- hash = helper_method0 params[:some_string] #does a request on a third party site which responds with json data wich is then parsed by yajl and the hash is returned to view 
%p= helper_method1 hash #Literally is just returning the input parameter 

我收到以下錯誤消息

Found multiple JSON objects in the stream but no block or the on_parse_complete callback was assigned to handle them. 

如何調用方法與輸入參數作爲從視圖中的另一種方法的返回?

回答

2

你在做什麼是完全正確的:)

而且你還可以這樣做:
(如果您想保存字節和變量)

%p= helper_method1(helper_method0 params[:some_string]) 

但無論如何。 ..
這個錯誤聽起來像json解析器中的問題...你使用的是Yajl

我一直在使用Yajl這樣的時候看到了這個問題:

parser = Yajl::Parser.new 
hash = parser.parse(some_string) 

什麼工作對我來說是使用Yajl類方法是這樣的:

Yajl::Parser.parse(some_string.strip) 

我希望這有助於:)