【问题标题】:Ruby on Rails autocomplete gem undefined local variableRuby on Rails 自动完成 gem 未定义的局部变量
【发布时间】:2012-03-26 19:08:49
【问题描述】:

我正在尝试使用 CrowdInteractive 的 rails3-jquery-autocomplete gem: https://github.com/crowdint/rails3-jquery-autocomplete/blob/master/README.md

但是我得到了这个错误:undefined local variable or method autocomplete_food_long_desc_foods_path' for #<#<Class:0xa17cf00>:0xa5ac724>

我知道以前有人问过这个问题,但我似乎仍然无法弄清楚我做错了什么。我按照自述文件中的所有说明进行操作,这是我的代码:

配方模型:

class Recipe < ActiveRecord::Base
  belongs_to :user
  has_many :foods, :through => :recipe_ingredients
  has_many :recipe_ingredients
end

recipe_ingredients 连接表模型:

class RecipeIngredient < ActiveRecord::Base
  belongs_to :recipe, 
  belongs_to :food, :foreign_key = 'ndb_no'
end

食品模型:

class Food < ActiveRecord::Base
  set_table_name 'foods'
  set_primary_key 'ndb_no'

  has_many :recipe_ingredients
  has_many :recipes, :through => 'recipe_ingredients'
end

基本的高级逻辑是一个菜谱有很多食物,食物可以属于几个菜谱。为此,我有一个名为 recipe_ingredients 的连接表,它还有一些更重要的字段。

我想对我的食谱控制器使用自动完成功能来查询食物表并获取单个食物。

配方控制器代码:

class RecipesController < ApplicationController
  include ApplicationHelper
  include RecipesHelper
  autocomplete :food, :long_desc
end

recipes/new 呈现这个部分形式:

<%= javascript_include_tag 'jquery', 'nested_form' %>
<%= javascript_include_tag "autocomplete-rails.js" %>
<%= f.autocomplete_field :food_long_desc, autocomplete_food_long_desc_foods_path %>

这是我的路线文件(我已经运行rake routes

resources :recipes do
  get :autocomplete_food_long_desc, :on => :collection
end

真诚感谢任何帮助。

【问题讨论】:

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


    【解决方案1】:

    关于或您路由正确的 URL 是:

    autocomplete_food_long_desc_recipes_path
    

    而不是

    autocomplete_food_long_desc_foods_path
    

    【讨论】:

    • 改变了我的看法 &lt;%= f.autocomplete_field :food_long_desc, autocomplete_food_long_desc_recipes_path %&gt; 但没有这样的运气。
    猜你喜欢
    • 2018-05-05
    • 1970-01-01
    • 2016-08-23
    • 2015-10-13
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多