开发者

Where do I insert my Rails URL in the JQuery Autocomplete to reference the data set I want?

Where do I reference my controller (Rails) URL to show the dataset that I want in the autocomplete via JQuery? Here is my head:

<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> 

Trying to figure out how to reference my controller or model (whichever I should) to get only records that are associated with a specific user_id. Just some frame of reference.

I have three tables, Users, Prospects, and Notes. Trying to set it up so that a specific user (user_id) can "add a note" and then use an autocomplete field to help "tag" to a prospect they have previously entered. I have already set up authentication and it is all working. JQuery seems to be getting me the closest. The head is above, and also I have uploaded jquery-1.3.2.js (though no reference to it yet as you can see in the head). Here is my prospects controller code:

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 开发者_JAVA技巧do |format|
      format.html { redirect_to(prospects_url) }

    end
  end
end


There's always Ryan Bate's Railscast on that subject. He's using the standard Rails autocomplete.

However, I prefer to use jQuery. I've used Dylan Verheul's autocomplete recently and found it very easy to set up.


try jquery autocomplete. i don't know anything about rails, but what you need to return to autocomplete should be easy enough even for a beginner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜