Rails 3 自动完成需要“id”=>“autocomplete_car_vin”

发布于 2024-12-09 01:50:34 字数 2663 浏览 0 评论 0原文

我的汽车表中有一个字段称为:vin(车辆识别号),我希望它在编写内容时使该字段自动完成......好吧,你们都知道我的意思。

我只想说重点..我在这里遵循了有关它的教程 https:// github.com/crowdint/rails3-jquery-autocomplete-app 它在新应用程序中运行得很好。因此,我决定将其放入我正在开发的应用程序中,我已经设置了应有的一切,但是当我在字段中输入字母时,我没有得到任何回报,显示屏上没有显示任何错误,但在控制台中我有这个:

 Started GET "/cars/autocomplete_car_vin?term=lh" for 127.0.0.1 at Sun Oct 09 07:50:06 +0300 2011
      Processing by CarsController#show as JSON
      Parameters: {"term"=>"lh", "id"=>"autocomplete_car_vin"}
      SQL (0.6ms)  SHOW TABLES
      Car Load (0.2ms)  SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 0 LIMIT 1
    Completed   in 38ms

    ActiveRecord::RecordNotFound (Couldn't find Car with ID=autocomplete_vin):
      app/controllers/cars_controller.rb:29:in `show'

参数采用我在本例中输入的字母 lh (这些是我记录中 VIN 号的前 2 个字母),对于我写的每个字母,我

"id"=>"autocomplete_vin" and  Couldn't find Car with ID=autocomplete_car_vin

在这里得到的是 Car.rb 中的几行

class Car < ActiveRecord::Base
  has_one :carname
  has_one :carmodel

一块 视图中的cars_controler

autocomplete :car, :vin

    def index
        @search = Car.search(params[:search])
        @cars = @search.all.paginate :page => params[:page], :per_page => 18

            respond_to do |format|
              format.html # index.html.erb
              format.xml  { render :xml => @cars }
              format.json { render :json => @cars.map(&:attributes) }
            end
          end

<%= form_tag do %>
  <%= autocomplete_field_tag 'vin', '',cars_autocomplete_car_vin_path %>
<% end %>

routes.rb中:get 'cars/autocomplete_car_vin' 我做了rake 路线并且我期望有一个自动完成的工作表单。 请帮助使其发挥作用。谢谢。

可能会有所帮助 - 这是控制台在教程应用程序中显示的内容,其中自动完成工作正常

写下第一个“me”字母会在自动完成中为我提供梅赛德斯,结果是

Started GET "/welcome/autocomplete_brand_name?term=me" for 127.0.0.1 at Sun Oct 09 04:04:57 +0300 2011
  Processing by WelcomeController#autocomplete_brand_name as JSON
  Parameters: {"term"=>"me"}
  Brand Load (0.6ms)  SELECT `brands`.* FROM `brands` WHERE (LOWER(name) LIKE 'su%') ORDER BY name ASC LIMIT 10
Completed 200 OK in 24ms (Views: 4.6ms | ActiveRecord: 0.6ms)

您看到没有“id”=>“此处需要“autocomplete_brand_name”。那么为什么我的应用程序控制台需要 ..., "id"=>"autocomplete_car_vin"} 这里有什么问题如果你们中有人可以帮助我,请做..我真的需要做这样我就可以继续前进。任何帮助和任何想法我都会很感激。提前致谢。

I have the car tables with a field in it called: vin (Vehicle Identification Number), I want it to make this field to autocomplete when writing something.. well, you all know what I mean.

I'll just get to the point.. I followed a tutorial about it here https://github.com/crowdint/rails3-jquery-autocomplete-app and it works great in a new app. So I decided to put this in my app that I work on, I've set up everything like it should be but when I type letters in the field I get nothing in return, no errors show in the display but in console I have this:

 Started GET "/cars/autocomplete_car_vin?term=lh" for 127.0.0.1 at Sun Oct 09 07:50:06 +0300 2011
      Processing by CarsController#show as JSON
      Parameters: {"term"=>"lh", "id"=>"autocomplete_car_vin"}
      SQL (0.6ms)  SHOW TABLES
      Car Load (0.2ms)  SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 0 LIMIT 1
    Completed   in 38ms

    ActiveRecord::RecordNotFound (Couldn't find Car with ID=autocomplete_vin):
      app/controllers/cars_controller.rb:29:in `show'

The paramaters takes the letters that I type in this case lh (these are first 2 letters from a VIN number in my records) and for each letter I write I get this

"id"=>"autocomplete_vin" and  Couldn't find Car with ID=autocomplete_car_vin

here is a few lines from Car.rb

class Car < ActiveRecord::Base
  has_one :carname
  has_one :carmodel

a piece of cars_controler

autocomplete :car, :vin

    def index
        @search = Car.search(params[:search])
        @cars = @search.all.paginate :page => params[:page], :per_page => 18

            respond_to do |format|
              format.html # index.html.erb
              format.xml  { render :xml => @cars }
              format.json { render :json => @cars.map(&:attributes) }
            end
          end

in view I have

<%= form_tag do %>
  <%= autocomplete_field_tag 'vin', '',cars_autocomplete_car_vin_path %>
<% end %>

in routes.rb: get 'cars/autocomplete_car_vin'
I did the rake routes and I expected an autocomplete working form.
Please help to make this working. Thanks.

Might help - here is what the console shows in a tutorial app where autocomplete works fine

Writing down the first me letters gives me mercedes in autocomplete as result

Started GET "/welcome/autocomplete_brand_name?term=me" for 127.0.0.1 at Sun Oct 09 04:04:57 +0300 2011
  Processing by WelcomeController#autocomplete_brand_name as JSON
  Parameters: {"term"=>"me"}
  Brand Load (0.6ms)  SELECT `brands`.* FROM `brands` WHERE (LOWER(name) LIKE 'su%') ORDER BY name ASC LIMIT 10
Completed 200 OK in 24ms (Views: 4.6ms | ActiveRecord: 0.6ms)

as you see there is no "id"=>"autocomplete_brand_name" required here. Why then my app console require the ..., "id"=>"autocomplete_car_vin"} what is the problem here if any of you can help me, please do.. I really need to do thid so I can move on. Any help and any idea I'll apreciate. Thanks in advance.

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

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

发布评论

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

评论(1

杯别 2024-12-16 01:50:34

在您的路线中,将自动完成行放在 resources :cars 行之前。

In your routes, put the autocomplete lines BEFORE the resources :cars line.

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