0

我在哪里引用我的控制器 (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 关联的记录。只是一些参考框架。

我有三个表,用户、前景和注释。尝试对其进行设置,以便特定用户 (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
4

2 回答 2

1

关于这个主题,总是有 Ryan Bate 的 Railscast。他正在使用标准的 Rails 自动完成功能。

但是,我更喜欢使用 jQuery。我最近使用了Dylan Verheul 的自动完成功能,发现它很容易设置。

于 2009-11-03T03:05:21.870 回答
0

尝试 jquery自动完成。我对rails一无所知,但是即使对于初学者来说,返回自动完成所需的东西也应该很容易。

于 2009-11-03T02:25:32.763 回答