我在哪里引用我的控制器(Rails)URL以通过JQuery在自动完成中显示我想要的数据集?这是我的头脑:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
$("#example").autocomplete(data);
});
</script>
试图找出如何引用我的控制器或模型(以我应该的方式)来获取仅与特定user_id相关联的记录。只是一些参考框架。
我有三个表,Users,Prospects和Notes。尝试进行设置,以便特定用户(user_id)可以“添加注释”,然后使用自动填充字段帮助“标记”他们之前输入的潜在客户。我已经设置了身份验证,它一切正常。 JQuery似乎让我最接近。头是在上面,我也上传了jquery-1.3.2.js(虽然没有参考它,但你可以看到头部)。这是我的前景控制器代码:
class ProspectsController < ApplicationController
before_filter :login_required
# GET /prospects
# GET /prospects.xml
def index
@prospects = current_user.prospects
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @prospects }
end
end
# GET /prospects/1
# GET /prospects/1.xml
def show
@prospect = current_user.prospects.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @prospect }
end
end
# GET /prospects/new
# GET /prospects/new.xml
def new
@prospect = Prospect.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @prospect }
end
end
# GET /prospects/1/edit
def edit
@prospect = current_user.prospects.find(params[:id])
respond_to do |format|
format.html # edit.html.erb
format.xml { render :xml => @prospect }
end
end
# POST /prospects
# POST /prospects.xml
def create
@prospect = current_user.prospects.create(params[:prospect])
respond_to do |format|
if @prospect.save
flash[:notice] = 'Prospect was successfully created.'
format.html { redirect_to(@prospect) }
format.xml { render :xml => @prospect, :status => :created, :location => @prospect }
else
format.html { render :action => "new" }
format.xml { render :xml => @prospect.errors, :status => :unprocessable_entity }
end
end
end
# PUT /prospects/1
# PUT /prospects/1.xml
def update
@prospect = current_user.prospects.find(params[:id])
respond_to do |format|
if @prospect.update_attributes(params[:prospect])
flash[:notice] = 'Prospect was successfully updated.'
format.html { redirect_to(@prospect) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @prospect.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /prospects/1
# DELETE /prospects/1.xml
def destroy
@prospect = Prospect.find(params[:id])
@prospect.destroy
respond_to do |format|
format.html { redirect_to(prospects_url) }
end
end
end
答案 0 :(得分:1)
Ryan Bate总是关于这个主题的Railscast。他正在使用标准的Rails自动完成功能。
但是,我更喜欢使用jQuery。我最近使用过Dylan Verheul's autocomplete,发现它很容易设置。
答案 1 :(得分:0)
尝试jquery autocomplete。我对rails没有任何了解,但是对于初学者来说,返回自动完成所需的内容应该很容易。