我正在使用IndexTank和Tanker gem在我的Rails应用程序上实现全文搜索,但是我得到了一个错误(URI::InvalidURIError错误URI(不是URI吗?))当尝试对我的索引使用search_tank方法时。
这是我得到错误的控制器方法
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)'我到处寻找答案,但我有点困惑。任何帮助都将不胜感激。
发布于 2012-03-26 07:41:32
这是一个URI.parse异常,它意味着某个url被错误地指定或生成。您确定您的配置设置正确吗?在https://github.com/kidpollo/tanker的自述文件中,您需要执行以下操作:
Initialization
如果您使用的是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仪表板提供的正确url
如果您已经这样做了,请仔细检查urls的拼写错误。
https://stackoverflow.com/questions/9865023
复制相似问题