我正在使用IndexTank和Tanker gem在我的Rails应用程序上实现全文搜索,但是在我的索引上尝试使用search_tank方法时出现错误(URI :: InvalidURIError错误URI(不是URI?))
这是我得到错误的控制器方法
def search
if params[:query]
@posts = Post.search_tank(params[:query], :page => 1, :per_page => 10)
else
@posts = []
end
end
这是我定义索引
的Post模型的一部分if ENV['RAILS_ENV'] === "production"
index = 'idx'
else
index = 'test'
end
tankit index do
indexes :title
indexes :description
end
# define the callbacks to update or delete the index
after_save :update_tank_indexes
after_destroy :delete_tank_indexes
我在rails控制台中测试时,search_tank方法有效。其他帖子似乎暗示这可能与config / routes.rb中设置的路由有关。我所设定的就是这个。
root :to => 'public#index'
match ':controller(/:action(/:id))(.:format)'
我一直在寻找答案,但我有点难过。任何帮助将不胜感激。
答案 0 :(得分:1)
这是一个URI.parse异常,这意味着某些url被错误地指定或生成。您确定正确设置了配置吗?在https://github.com/kidpollo/tanker的自述文件中,您需要执行以下操作:
<强>初始化强>
如果你正在使用Rails,config / initializers / tanker.rb是个好地方 为此:
YourAppName::Application.config.index_tank_url = 'http://:xxxxxxxxx@xxxxx.api.indextank.com'
如果您没有使用rails,可以在加载之前将其放在某处 你的模特
Tanker.configuration = {:url => 'http://:xxxxxxxxx@xxxxx.api.indextank.com' }
您可能希望拥有更好的配置,具体取决于 你的环境。请务必复制并粘贴提供的正确网址 由IndexTank Dashboard
如果您已经这样做了,请仔细检查网址上的拼写错误。