Note that there are some explanatory texts on larger screens.

plurals
  1. PORender from AJAX request
    primarykey
    data
    text
    <p>I am making a simple Ajax request and trying to render it, but I just dont figure out how.</p> <p>This is the form:</p> <pre><code>&lt;%= form_tag(root_path, :method =&gt; "post",:id =&gt;"formid", :remote =&gt; true) do %&gt; &lt;%= label_tag(:number1, "El que quiero") %&gt; &lt;%= text_field_tag :quiero, nil, :class =&gt; 'drug_autocomplete' %&gt; &lt;%= hidden_field_tag :number1 %&gt; &lt;%= label_tag(:number1, "El modelo que tengo") %&gt; &lt;%= text_field_tag :tengo, nil, :class =&gt; 'drug_autocomplete' %&gt; &lt;%= hidden_field_tag :number2 %&gt; &lt;%= label_tag(:size1, "Talla de el que tengo") %&gt; &lt;%= text_field_tag :size1%&gt; &lt;%= submit_tag("Do it!",:id =&gt;"submit_but") %&gt; &lt;% end %&gt; </code></pre> <p>This is pretty much the controller</p> <pre><code>def index size1 = params[:size1] number1 = params[:number1] number2 = params[:number2] quiero = params[:quiero] tengo = params[:tengo] if (item1 and item2) @itemsok = Contribution.where("first_item_id = ?",item1.id).where("second_item_id = ?",item2.id).where("second_item_grade = ?",size1) end </code></pre> <p>Ok, so when I push the button to send, I can see that the consult in the database is being made, when I write correct values it returns it and all works perfectly.</p> <p>What I dont know how to do is to render the items from the query. In the view I have a table where I want to fill the information in... I've already done it without AJAX, and it is like this.</p> <pre><code>&lt;%if not @itemsok.nil? @itemsok.each do |searches| %&gt; &lt;table&gt; &lt;tr&gt; &lt;td style="width:100px;"&gt;&lt;%= searches.first_item.description %&gt; &lt;/td&gt; &lt;td style="width:150px; font-size:30px;"&gt;&lt;%= searches.first_item_grade %&gt; &lt;/td&gt; &lt;td style="width:150px;"&gt;&lt;%= searches.second_item.description %&gt; &lt;/td&gt; &lt;td style="width:150px; font-size:30px;"&gt;&lt;%= searches.second_item_grade %&gt; &lt;/td&gt; &lt;td style="width:150px; font-size:18px;"&gt;&lt;a href="&lt;%= contribution_path(searches.id) %&gt;"&gt;Show&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Ok, so it takes the variable in the controller, and if is not nill, it renders the data (wich in a normal request, I can access reloading the page)</p> <p>How can I render the items from my query? Any hint would be very appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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