User
模型已使用ThinkingSphinx
定义要搜索的索引。但是,当我停止我的searchd
deamon时,我希望我的方法优雅地失败并且不会抛出错误。通常我通过使用一个救援块捕捉异常来做到这一点。但在这种情况下,它仍然会抛出错误,并且从不执行语句puts
。Rails没有在救援块中发现异常
def search_users(key)
begin
search_results = User.search(key,options)
rescue Exception
puts "Hello World!!!"
search_results = []
end
return search_results
end
以下是错误我得到:
Riddle::ConnectionError (Connection to 127.0.0.1 on 3201 failed. Connection refused - connect(2)):
有什么办法呢?
试过这个:https://groups.google.com/forum/?fromgroups=#!topic/thinking-sphinx/PGT22AqAvZo? – Zabba
完美!解决了。非常感谢 :) – atmaish