Note that there are some explanatory texts on larger screens.

plurals
  1. PORails, session and rendering partial with session variables via AJAX, have to work but not working
    primarykey
    data
    text
    <p>I have a button, when I click on it, liked product ID is stored in the session. Everything happens through AJAX.</p> <p>At the bottom of the page I want to see saved products and want they updated automatically via jQuery. But div appears only if I refresh the page.</p> <p>Everything seems to be correct, but does not work.</p> <p>My link:</p> <pre><code>&lt;%= link_to "", remember_url(prop.id), method: :post, id: 'remember_me', class: "like #{like prop.id}", data: { href: remember_url(prop.id)}, remote: true %&gt; </code></pre> <p>My method in controller:</p> <pre><code> def remember_me session[:product] ||= [] products_array = session[:product] product = Product.find(params[:id]) if products_array.include? product.id products_array.delete(product.id) else products_array &lt;&lt; product.id end #redirect_to :back #render :nothing =&gt; true render partial: "static_pages/debag" #=&gt; this is going to be "result" in AJAX. end </code></pre> <p>render partial: 'static_pages/debag:</p> <pre><code>&lt;%= session[:houses] %&gt; </code></pre> <p>ajax:</p> <pre><code>$('a.like').click(function() { $.ajax({ url: $(this).data('href'), type: 'POST', dataType: 'html', success: function(){ suppose here I have to refresh session? $(".session").html("&lt;%= j(render(partial: 'static_pages/debag')) %&gt;"); } }); }); </code></pre> <hr> <p>Solution: Answer was weird. But now it's working. Just added result to function and into html.</p> <pre><code>$('input#start_page, a.like').click(function() { $.ajax({ url: $(this).data('href'), type: 'POST', dataType: 'html', success: function(result){ $(".session").html(result); } }); }); </code></pre>
    singulars
    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.
    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