how to test jquery autocomplete in rails that isn't responding
I'm trying to use rails3-jquery-autocomplete gem on OSX 10.7, Rails 3.1.0, Ruby 1.9.2-p290
I just set up a pretty blank app to find out why I cant get it to work. I don't get any error messages but nothing is appearing. I don't know what to fix.
Here's what I have:
<head>
<title>Usewith</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "autocomplete-rails.js" %>
<%= csrf_meta_tags %>
</head>
ItemsController
class ItemsController < ApplicationController
# GET /items
# GET /items.json
autocomplete :category, :name
Routes.rb
Usewith::Application.routes.draw do
resources :items do
get :autocomplete_category_name, :on => :collection
end
resources :categories
items/_form.html.erb
<div class="field">
<%= f.label :category_id %><br />
<%= f.collection_select :category_id, Category.all, :id, :name %>
<%= f.autocomplete_field :category_name, autocomplete_category_name_items_path %>
</div>
Item model contains category_id:integer, category_name:string
Any help on where to start looking?
EDIT I receive this error in Chrome console
Uncaught TypeError: Object [object Object] has no method > 'autocomplete' jQuery.railsAutocomplete.fn.extend.init autocomplete-rails.js:53 jQuery.railsAutocomplete autocomplete-rails.j开发者_如何学JAVAs:35 jQuery.fn.railsAutocomplete autocomplete-rails.js:28 liveHandlerjquery.js:3689 jQuery.event.handle jquery.js:2966 jQuery.event.add.elemData.handle.eventHandle jquery.js:2600 jQuery.event.triggerjquery.js:2894 handler jquery.js:3420
autocomplete-rails.js:53
$(e).autocomplete({
I've never used jquery autocomplete but anytime I'm debugging jquery/javascript I use Chrome and the developer tools. The shortcut to bring it up is alt-cmd-I from Chrome
From there you can look at the "Network" tab to see if any requests are being made, even xhr requests. Clicking on a request will show the headers, content, cookies, etc. I'd say that's a good place to start.
If you use Firefox then you can use firebug, basically the same thing.
Btw, as I was typing up this answer I saw SO get the following response :) Apparently for autosaving answer drafts.
{"message":"0","draftSaved":true,"disableEditor":false}
silly answer but I realised I need to add in
//= require jquery-ui
to the new application.js
and also
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/ui-lightness/jquery-ui.css" %>
to application.html.erb
精彩评论