Rails-3jquery-automcomplete 路径助手未返回 Rails 3.1.1 中的正确路径

发布于 2024-12-09 01:38:17 字数 1554 浏览 0 评论 0原文

我有一个模型:

class EvidenceType < ActiveRecord::Base
  has_many :evidences

  attr_accessible :name

end

控制器:

class EvidencesController < ApplicationController

  autocomplete :evidence_type, :name

在我看来:

<%= form_tag do %>            
    <%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>
<% end %>

在 Routes.rb 中:

resources :evidences do
  get :autocomplete_evidence_type_name, :on => :collection
end

rake 路线给了我:

autocomplete_evidence_type_name_evidences GET    /evidences/autocomplete_evidence_type_name(.:format) {:action=>"autocomplete_evidence_type_name", :controller=>"evidences"} 

当我开始在自动完成字段中输入时,我在 Rails 日志中看到一个请求:

Started GET "/autocomplete/evidences/autocomplete_evidence_type_name?term=co" for 127.0.0.1 at Tue Oct 11 17:45:57 +0100 2011

ActionController::RoutingError (No route matches [GET] "/autocomplete/evidences/autocomplete_evidence_type_name"):

如果我手动转到 http://localhost:3000/evidences/autocomplete_evidence_type_name?term=xx 然后我得到返回的所需片段,这让我相信一切似乎都用 jquery 正确地粘合在一起。

我想我要么需要在我的路线中添加一个额外的“自动完成”(看起来很黑客?),要么我的 autocomplete_evidence_type_name_evidences_path 帮助程序需要将 /autocomplete 从前面删除。

不过话虽如此,我却怀疑,可能是我做错了什么?有什么想法吗?

I have a model:

class EvidenceType < ActiveRecord::Base
  has_many :evidences

  attr_accessible :name

end

A controller:

class EvidencesController < ApplicationController

  autocomplete :evidence_type, :name

In my view:

<%= form_tag do %>            
    <%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>
<% end %>

In Routes.rb:

resources :evidences do
  get :autocomplete_evidence_type_name, :on => :collection
end

rake routes gives me:

autocomplete_evidence_type_name_evidences GET    /evidences/autocomplete_evidence_type_name(.:format) {:action=>"autocomplete_evidence_type_name", :controller=>"evidences"} 

When i start typing in the autocomplete field i see a request int the rails log:

Started GET "/autocomplete/evidences/autocomplete_evidence_type_name?term=co" for 127.0.0.1 at Tue Oct 11 17:45:57 +0100 2011

ActionController::RoutingError (No route matches [GET] "/autocomplete/evidences/autocomplete_evidence_type_name"):

If I manually go to http://localhost:3000/evidences/autocomplete_evidence_type_name?term=xx then i get the desired snippet returned, which leads me to believe everything seems to be glued together properly with jquery.

I figure I either need to add an extra 'autocomplete' to my route (seems hackish?) or that my autocomplete_evidence_type_name_evidences_path helper needs to drop the /autocomplete off of the front.

However, having said this, I suspect that it might be me that is doing something wrong? Any ideas?

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

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

发布评论

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

评论(1

獨角戲 2024-12-16 01:38:18

在这一行:

<%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>

您不需要 :autocomplete =>。这就是向 URL 添加额外的 /autocomplete 的原因。只需使用:

<%= autocomplete_field_tag 'evidence', '', autocomplete_evidence_type_name_evidences_path %>

我使用这个 gem 一段时间了,除非过去几个月发生了一些变化,否则应该会为您修复它。

On this line:

<%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>

You don't need :autocomplete =>. That is what's adding the extra /autocomplete to the URL. Just use:

<%= autocomplete_field_tag 'evidence', '', autocomplete_evidence_type_name_evidences_path %>

I used this gem for a while and unless something has changed in the past few months, that should fix it for you.

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