Rails 3 自动完成需要“id”=>“autocomplete_car_vin”
我的汽车表中有一个字段称为: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的路线中,将自动完成行放在
resources :cars
行之前。In your routes, put the autocomplete lines BEFORE the
resources :cars
line.