Rails思维狮身人面像方法

发布于 2024-12-17 11:45:18 字数 1109 浏览 2 评论 0原文

我正在尝试在我的 Rails 3 应用程序中设置 Think Sphinx。我设置mysql并安装sphinx没有错误。在我的 gemfile 中,

gem "riddle", "~> 1.5.0"
gem "thinking-sphinx", "~> 2.0.10"

这些安装得很好。在我的模型中

define_index do
    indexes :name
    indexes acad_field
    indexes expertise
    indexes interests
    indexes experience
    indexes marital_status
    indexes email
    indexes place_of_birth
    indexes birthyear
    indexes hometown
    indexes current_residence
    indexes languages
    indexes nationalities
    indexes ethnicities_mom_dad
    indexes institution
    indexes program

end

,我在控制器的索引中,

def index
 #@profiles = Profile.all
 @profiles = Profile.search params[:search]
 respond_to do |format|
   format.html # index.html.erb
   format.json { render :json => @profiles }
 end
end

在我的路线中,

match "profiles?search=:search", :to => "profiles#index"

当我尝试运行搜索时,我收到错误“

Routing Error

undefined method `define_index' for #<Class:0xb3ada670>

我在这里做错了什么”。

Im trying to set up thinking sphinx in my rails 3 app. I set up mysql and installed sphinx without error. In my gemfile i have

gem "riddle", "~> 1.5.0"
gem "thinking-sphinx", "~> 2.0.10"

These install fine. In my model i have

define_index do
    indexes :name
    indexes acad_field
    indexes expertise
    indexes interests
    indexes experience
    indexes marital_status
    indexes email
    indexes place_of_birth
    indexes birthyear
    indexes hometown
    indexes current_residence
    indexes languages
    indexes nationalities
    indexes ethnicities_mom_dad
    indexes institution
    indexes program

end

and in my index in my controller i have

def index
 #@profiles = Profile.all
 @profiles = Profile.search params[:search]
 respond_to do |format|
   format.html # index.html.erb
   format.json { render :json => @profiles }
 end
end

in my routes i have

match "profiles?search=:search", :to => "profiles#index"

when i try running a search i get the error

Routing Error

undefined method `define_index' for #<Class:0xb3ada670>

What i am doing wrong here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愿与i 2024-12-24 11:45:18

我只需要

rake thinking_sphinx:rebuild

在终端中运行

I just needed to run

rake thinking_sphinx:rebuild

in terminal

花辞树 2024-12-24 11:45:18

根据 @fuzzyalej 评论,所需的步骤是:

  • 将相应的 gem 行替换为 gem "thinking-sphinx", "~> 2.0.10", :require => 'thinking_sphinx'
  • 您不需要将 ?search=:search 添加到路由匹配中,因为 Rails 可以接受 GET 变量而无需其他规范。

Based on @fuzzyalej comment, the needed steps are:

  • Replace correspondent gem line to gem "thinking-sphinx", "~> 2.0.10", :require => 'thinking_sphinx'
  • You do not need add ?search=:search to routing match, because rails can accept GET variables without other specifications.
一人独醉 2024-12-24 11:45:18

在 gemfile 中添加 gem 规范后,您可能没有运行“bundle install”,我不认为 rake ts:rebuild 实际上解决了这个问题:)

you probably didn't run 'bundle install' after adding the gem specification in your gemfile, I don't think rake ts:rebuild actually solved this issue :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文