简体   繁体   English

auto_complete插件错误:找不到ID = auto_complete_for_的问题

[英]auto_complete plugin error: Couldn't find Question with ID=auto_complete_for_

I have successfully set up this plugin before so I am curious as to what I am doing wrong here. 我之前已经成功设置了此插件,因此我对自己在这里做错了很好奇。 I have built the ability for users to add tags to questions. 我已经建立了供用户向问题中添加标签的功能。 I am not using tagging plugin here but that shouldn't matter for this. 我没有在这里使用标签插件,但这无关紧要。

With respect to the auto complete, I am trying to have the form located in the /views/questions/show.html.erb file access the Tags table and display entries in the tags.tags_name column. 关于自动完成功能,我正在尝试让/views/questions/show.html.erb文件中的/views/questions/show.html.erb访问“标记”表并在“ tags.tags_name列中显示条目。

When I begin to type in the field I get the following error message: 当我开始在字段中键入时,出现以下错误消息:

Processing QuestionsController#show (for 127.0.0.1 at 2010-05-31 15:22:20) [GET]
  Parameters: {"tag"=>{"tag_name"=>"a"}, "id"=>"auto_complete_for_tag_tag_name"}
  Question Load (0.1ms)   SELECT * FROM "questions" WHERE ("questions"."id" = 0) 

ActiveRecord::RecordNotFound (Couldn't find Question with ID=auto_complete_for_tag_tag_name):
  app/controllers/application_controller.rb:15:in `init_data'

For some reason I am actually passing the field name as the Question.id. 由于某种原因,我实际上将字段名称传递为Question.id。

The plugin set up is fairly simple as you add the following line to your controller: 在您将以下行添加到控制器时,插件设置非常简单:

auto_complete_for :tag, :tag_name

and the following line in your routes.rb file: routes.rb文件中的以下行:

map.resources :tags, :collection => {:auto_complete_for_tag_tag_name => :get }

I have added the controller line to both my tags and questions controller and also mapped resources for both tags and questions in my routes.rb file: 我已将控制器行添加到标签和问题控制器中,并且还在我的routes.rb文件中映射了标签和问题的资源:

map.resources :tags, :collection => {:auto_complete_for_tag_tag_name => :get }
map.resources :questions, :collection => {:auto_complete_for_tag_tag_name => :get }

I have played around with removing either or of the above but can't seem to fix it. 我已经尝试删除上述任何一个,但似乎无法修复。 Any ideas what I am doing wrong here? 有什么想法我在这里做错了吗?

UPDATE: 更新:

My QuestionsController#show action is fishing posts by: 我的QuestionsController#show动作通过以下方式钓鱼:

@question = Question.find(params[:id])

Found the answer. 找到了答案。 Crazy. 疯。 You just have to add this to your routes.rb file: 您只需将其添加到您的routes.rb文件中:

map.auto_complete ':controller/:action',
     :requirements => { :action => /auto_complete_for_\S+/ },
     :conditions => { :method => :get }

Here is where I found it. 这是我找到的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM