【问题标题】:rails3-jquery-autocomplete not workingrails3-jquery-autocomplete 不工作
【发布时间】:2012-10-16 19:08:50
【问题描述】:

我正在学习本教程 [https://github.com/crowdint/rails3-jquery-autocomplete][1],但我遇到了问题。

我的模型:

class Category < ActiveRecord::Base
  attr_accessible :name

  has_many :products
end

class Product < ActiveRecord::Base
  attr_accessible :name, :category_id

  belongs_to :category
end

架构:

  create_table "categories", :force => true do |t|
    t.string   "name"
  end

  create_table "products", :force => true do |t|
    t.string   "name"
    t.integer  "category_id"
  end

这是我的控制器:

autocomplete :category, :name

我的布局是这样的:

<%= javascript_include_tag :defaults, "autocomplete-rails.js"  %>

我的路线有这个:

  resources :products do
    get :autocomplete_category_name, :on => :collection
  end

我的表格是这样的:

<%= f.autocomplete_field :category_name, autocomplete_category_name_products_path %>

我的 app/assets/javascript 文件夹中有 autocomplete-rails.js。然而由于某种原因,我不断收到此错误:

undefined method `category_name'

【问题讨论】:

  • 更新路由后是否重启了网络服务器?

标签: ruby-on-rails gem jquery-autocomplete


【解决方案1】:

你应该使用

<%= f.autocomplete_field :category, autocomplete_category_name_products_path, :id_element => '#product_category_id' %>
<%= f.hidden_field :category_id %>

【讨论】:

    【解决方案2】:

    确保您已安装并捆绑了 gem,然后再次重新启动服务器

    gem 'rails3-jquery-autocomplete`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 2016-02-04
      • 2013-06-25
      相关资源
      最近更新 更多