当没有模型时使用 Rails jQuery 自动完成
jQuery 自动完成文档指出应该有两个模型,第一个是您要用于自动完成的模型,第二个是具有第一个模型(并附加到您的页面)的模型。但是,我没有第二个模型,只有一个带有表单元素的视图的控制器,其中一个是第一个模型(地点)的自动完成输入。
文档说我应该这样做
resources :parse do
get :autocomplete_venue_name, :on => :collection
end
,但这不会起作用,因为控制器“解析”没有模型。我尝试制作静态路由,但我需要 :collection 选项。我该如何解决这个要求?
编辑: 下面是来自 Rails+jquery 自动完成插件的代码。请注意,我有一个 ProductsController,但没有 Products 模型,因此我无法执行routes.rb 设置:
class Brand < ActiveRecord::基础 最终
要搜索的
create_table :brand do |t|
t.column :name, :string
end
模型:具有所需自动完成形式的控制器:
class ProductsController < Admin::BaseController
autocomplete :brand, :name
end
ROUTES.RB
resources :products do
get :autocomplete_brand_name, :on => :collection
end
此方法仅在我有产品模型时才有效,而我没有。我有一个控制器,它显示带有自动完成输入的表单。
jQuery autocomplete docs state there should be two Models, the first being the model that you want to use for autocomplete, the second being the model that has the first Model (and is attached to your page). However, I don't have the second model, just a Controller w/view that has form elements, one of them an autocomplete input of the first Model (Venue).
The docs say I should do
resources :parse do
get :autocomplete_venue_name, :on => :collection
end
But that won't work since the controller 'Parse' doesn't have a model. I tried making a static route but I need that :collection option. How can I work around this requirement?
EDIT:
Below is the code from the rails+jquery autocomplete plugin. Note that I have a ProductsController but I don't have a Products model, so I can't do the routes.rb setup:
class Brand < ActiveRecord::Base
end
MODEL TO SEARCH ON:
create_table :brand do |t|
t.column :name, :string
end
CONTROLLER WITH DESIRED AUTOCOMPLETE FORM:
class ProductsController < Admin::BaseController
autocomplete :brand, :name
end
ROUTES.RB
resources :products do
get :autocomplete_brand_name, :on => :collection
end
This approach works only if I have a Products model, which I do not. I have a Controller that is displaying a form w/autocomplete inputs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用 jquery 多自动完成插件,您可以在其中选择一个或多个自动
完成值,如果没有模型,那么它将工作,例如
$(document).ready(function() {
在我的情况下 @tags = Tag.all
但是您可以在控制器操作中给出任何其他值。其模型不存在
就像控制器
@tags = ["cute","beauty","amazing"]
我用于多重自动完成的代码如下,
但您应该包括 。一些jquery自动完成js从那里下载文件
jquery.ui.core
jquery.ui.widget
jquery.ui.position
jquery.ui.autocomplete
I am using jquery multi auto complete plugin in which you can select one or multi auto
complete value and if there is no model then it will work e.g
$(document).ready(function() {
in my case @tags = Tag.all
But you can give any other values in controller action.Whose model is not exist
Like in controller
@tags = ["cute","beauty","amazing"]
The code i am using for multi Autocomplete is below.
But you should include some jquery auto complete js files from jquery.UI.Download files from there and include in project.
jquery.ui.core
jquery.ui.widget
jquery.ui.position
jquery.ui.autocomplete