我正在关注此视频http://railscasts.com/episodes/258-token-fields-revised,我也成功实施了此视频。但现在我正在使用命名空间。 我在资产文件夹里面的文件夹员工里面有lends_controller。 这是我的借出控制器模型
class Employee::Asset::Lend
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :text, type: String
field :date
field :asset_tokens
field :user_id, type: String
has_and_belongs_to_many :assets
belongs_to :tags
def asset_tokens=(tokens)
self.asset_ids = Asset.ids_from_tokens(tokens)
end
end
现在我有另一个模型资产。我必须定义has和属于这个借出模型我也做了这个
class Asset
include Mongoid::Document
field :name, type: String
field :description, type: String
field :serial_number, type: String
field :status, type: Integer
field :tag_tokens
field :quantity, type: Integer
validates_presence_of :name
validates :serial_number,:uniqueness => true
has_and_belongs_to_many :employee_asset_lends
has_and_belongs_to_many :tags
def self.tokens(query)
assets = where(name: /#{Regexp.escape(query)}/i)
end
借出控制器的表格是
<%= f.label :asset_tokens, "Assets" %>
<%= f.text_field :asset_tokens, data: {load: @employee_asset_lend.assets}%><br>
<%= f.input :date,:input_html => { :class => "dp1"},:label=> "Lend Date"%>
在lend.js.coffee的coffescript文件中
jQuery ->
$('#employee_asset_lend_asset_tokens').tokenInput '/assets.json'
theme: 'facebook'
prePopulate: $('#employee_asset_lend_asset_tokens').data('load')
但是错误uninitialized constant EmployeeAssetLend from asset views.
从lend视图中,它为Employee :: Asset:Module`提供了undefined method
all_of'之类的错误