【发布时间】:2012-02-29 04:12:48
【问题描述】:
我正在尝试实现 Thinking Sphinx 2.0.10,据我了解,它与 Rails 3 兼容。我对使用 Ruby on Rails 进行编程非常陌生。我浏览了很多关于 StackOverflow 的文章,但找不到解决问题的方法。
我在 Gemfile 中安装了没有 :require 参数的 gem。
gem 'thinking-sphinx', '2.0.10'
我有一个可用的 Rails 应用程序,它显示了一个我想添加搜索的列表。
这是我在模型文件中定义索引的代码。
define_index do
indexes :email, :sortable => true
indexes :name, :sortable => true
indexes microposts.content, :as => :micropost_content
end
这是我的控制器文件中的 Rails 代码。注释掉的行是正在工作的原始代码。我有一个默认的 will_paginate 我认为在应用程序控制器中每页 15 条记录。
def index
@users = User.search params[:search], :per_page => 15
# @users = User.paginate(page: params[:page])
end
这是我添加到索引页的搜索框。
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
这是我的 rSpec 代码。这是我在尝试实现 Thinking Sphinx 之前使用的原始代码。
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before(:each) do
sign_in user
visit users_path
end
it { should have_selector('title', text: 'All users') }
describe "pagination" do
before(:all) { 15.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
let(:first_page) { User.paginate(page: 1) }
let(:second_page) { User.paginate(page: 2) }
it { should have_link('Next') }
it { should have_link('2') }
it { should_not have_link('delete') }
it "should list each user" do
User.all[0..2].each do |user|
page.should have_selector('li', text: user.name)
end
end
it "should list the first page of users" do
first_page.each do |user|
page.should have_selector('li', text: user.name)
end
end
it "should not list the second page of users" do
second_page.each do |user|
page.should_not have_selector('li', text: user.name)
end
end
describe "as an admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before do
sign_in admin
visit users_path
end
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect { click_link('delete') }.to change(User, :count).by(-1)
end
it { should_not have_link('delete', href: user_path(admin)) }
end
end
end
当我运行 rSpec 测试时,我收到以下错误:
Failure/Error: visit users_path
ActionView::Template::Error:
getaddrinfo: nodename nor servname provided, or not known
页面显示得很好。当我在搜索框中输入文本并单击按钮时,没有任何反应,这对我来说并不奇怪。
我可以在终端上运行 Sphinx。搜索工作正常。我只是不知道如何用 Thinking Sphinx 调试这个问题。在过去的几天里,我搜索了这个网站上的许多页面和许多其他页面,但没有一个页面处理这个问题。任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails-3 rspec2 thinking-sphinx