【发布时间】:2012-06-07 21:31:16
【问题描述】:
我正在尝试在字段上运行 tokeninput 插件。
首先,本教程主要是关于从另一个关联模型添加 id。我不想这样做,而只是使用我自己的模型(表)中名为 tags 的字段。
目前,当我输入它时,它会执行 /notes/tags.json ajax 调用,但没有返回任何内容,我这样做对吗?
控制器:
class NotesController < ApplicationController
helper_method :sort_column, :sort_direction
respond_to :html, :json
def index
@notes = Note.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 5, :page => params[:page])
@tag = Note.where('tag LIKE ?', "%#{params[:q]}%")
end
型号:
class Note < ActiveRecord::Base
attr_accessible :name, :tag
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
end
【问题讨论】:
-
我的路线只是普通的“资源:notes”我的意思是不同的吗?令牌输入也应该与我的使用方式一起使用吗?无论如何,我什至没有得到 json 回报。
-
/notes/tags.json 不映射到路由。 . .有没有可以在 github 上发布的示例项目?您需要做的不止一件事
-
如果您尝试在浏览器中访问 /notes/tags.json,您应该会收到路由错误
-
你能添加你的 tokeninput javascript 代码吗?
标签: ruby-on-rails ruby-on-rails-3 jquery jquery-tokeninput