Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Tokeninput Error in Rails
    primarykey
    data
    text
    <p>I'm trying to use jQuery Tokeninput as shown in Railscast #258 (revised). When I enter something in the tokeninput field, the field does not dropdown with results and I get the following javascript error: <code>Uncaught TypeError: Cannot call method 'replace' of undefined</code>.</p> <p>My json data works fine when I do a manual query on it, and the server request looks fine. I am trying to search the content column in my issues table, so I set propertyToSearch to "content".</p> <p>Here is my code: </p> <p>coffeescript: </p> <pre><code>jQuery -&gt; $('#fact_issue_tokens').tokenInput "/issues.json" theme: 'facebook' zindex: 11001 propertyToSearch: 'content' tokenValue: 'content' hintText: 'Enter an issue' preventDuplicates: true </code></pre> <p>Issue Model: </p> <pre><code>def self.tokens(query) issues = where("content like ?", "%#{query}%") if issues.empty? [{id: "&lt;&lt;&lt;#{query}&gt;&gt;&gt;", content: "New: \"#{query}\""}] else issues end end def self.ids_from_tokens(tokens) tokens.gsub!(/&lt;&lt;&lt;(.+?)&gt;&gt;&gt;/) { create!(content: $1).id } tokens.split(',') end </code></pre> <p>Issues Controller:</p> <pre><code>def index @issues = Issue.order(:content) respond_to do |format| format.html format.json { render json: @issues.tokens(params[:q]) } end end </code></pre> <p>Form: </p> <pre><code>&lt;%= form_for(Fact.new, :url =&gt; kase_facts_path(current_kase), :html =&gt; {:class =&gt; "form- inline"}) do |f| %&gt; &lt;%= f.text_field :page, placeholder: 'Page' %&gt; &lt;%= f.text_field :description, placeholder: 'Description' %&gt; &lt;%= f.label :issue_tokens, 'Issue tags' %&gt; &lt;%= f.text_field :issue_tokens %&gt; &lt;%= f.hidden_field :source_id, :value =&gt; @source.id %&gt; &lt;%= f.submit 'Add Fact' %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload