开发者

rails 3 autocomplete requires "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/c开发者_如何学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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜