自动完成生成路由错误

时间:2013-09-05 19:43:57

标签: ruby-on-rails ruby-on-rails-3 autocomplete

我有模型hotel,其属性为:id, hotel_name

我在家庭控制器上应用了自动完成功能

class HomeController < ApplicationController
  autocomplete :hotel, :hotel_name, :full => true
end

和路线是:

resources :hotels do
    collection do
      get 'autocomplete_hotel_hotel_name'
    end
end
视图上的

<%= form_tag do %>
    <%=autocomplete_field_tag 'hotel_name', '', :autocomplete => autocomplete_hotel_hotel_name_hotels_path %>
  <% end %>

但是当我输入文本字段时,它会产生路由错误。

在链接上生成路由错误

  

“NetworkError:404 Not Found -   为myhost:3000 /%7B:自动填充=%3E%22 /酒店/ autocomplete_hotel_hotel_name%22%7D术语= VI “”

当我解码这个URL时,它看起来像:

  

NetworkError:404 Not Found -   为myhost:3000 / {:自动填充=&gt; “中/酒店/ autocomplete_hotel_hotel_name”}术语= VI“

因此,它没有生成正确的自动填充网址

1 个答案:

答案 0 :(得分:1)

Autocomplete_field_tag希望您传递这样的参数:

autocomplete_field_tag 'hotel_name', '', autocomplete_hotel_hotel_name_hotels_path

第三个参数不应该是哈希。


您还需要在HotelsController中指定您想要自动完成:

class HotelsController < ApplicationController
  autocomplete :hotel, :hotel_name, :full => true