我試圖在字段上運行tokeninput插件。令牌輸入在rails中不起作用
首先教程主要是圍繞增加的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
你有沒有設置路線? –
也我想你想這個:http://jqueryui.com/demos/autocomplete/#multiple-remote –
我的路線只是正常的'資源:筆記'我的意思是不同的東西?也應該令牌輸入與我如何使用它的工作?反正我甚至沒有得到json的回報。 – user979587