我有一个字段在其中的汽车表名为:vin(车辆识别号码),我希望它使这个字段在写东西时自动完成。好吧,你都知道我的意思。rails 3自动完成需要“id”=>“autocomplete_car_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'
的PARAMATERS需要,我在这种情况下,LH(这些都是从我的记录VIN号前两个字母)的字母,每个字母我写我得到这个
"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'
我做耙路由和我的预期的自动完成工作表单。 请帮助使此工作。谢谢。
可能有助于 - 这里是控制台显示了教程应用程序,其中自动完成正常工作
写下第一我写信给我在自动完成奔驰作为结果
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"}
这里有什么问题,如果你们中的任何人都可以帮助我,请做..我真的需要做到这一点,所以我可以继续前进。任何帮助和任何想法,我会apreciate。提前致谢。
是的,我的朋友..很简单,但我不知道它,谢谢你一百万次,你又救了我。 – rmagnum2002
你还救了我几个小时我猜:) – register