Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I properly refresh a partial that renders a partial (refreshing via js results in page in a page)
    primarykey
    data
    text
    <p>Update 2 - marzapower's came through again.. the success section in the ajax was causing the problem - the explanation below..</p> <p>UPDATE: </p> <p>marzapower's answer works well (see it below) but I needed this on a timer. </p> <p>Works on the first time, but on reload it displays html markup instead of just the content.. I tried html_safe int refreshnews.js.erb file but it still doesn't work. </p> <p>If I use single quotes before &lt;% %> it bombs because 'news/newsfeed' has them too - kept single quotes and changes the partial name to double quotes.. still doesn't work right..</p> <p>refreshnews.js.erb:</p> <pre><code>$("#refreshscribbles").html("&lt;%= j(render(:partial=&gt; 'news/newsfeed', :locals=&gt;{:news=&gt;@news}).html_safe) %&gt;"); </code></pre> <p>I've tried all kinds of changes - single quotes, .html_safe on the outer right parenthesis, etc.. but this is what i get instead of clean content.</p> <p>RETURNED CONTENT:</p> <p><img src="https://i.stack.imgur.com/11UDO.png" alt="sample output"></p> <pre><code>news.js $(document).ready(function() { setInterval( function() { $.ajax({ url: '/refreshnews.js', type: 'GET', dataType: 'script', success: function(result) { $('#refreshscribbles').html(result) } }); } , 500); }); </code></pre> <p>Otherwise, the solution is perfect - any ideas why html_safe isn't working? Should I do something in the format.js ?</p> <hr> <p>I have a news feed that I'm working on (think facebook news feed). I need to update the feed without reloading the entire page again. (The entire feed loads at once - it is not a bunch of small loads.. Rather one big load.. like returning data from a sql select)</p> <p>I'm dynamically rendering a partial which renders another partial based upon values in the data..</p> <p>I stole a javascript solution, and worked it into my form, but the minute it reloads the div section it uses the application layout. I've tried layout=>false etc to no avail. I've tried in the format.js respond_to section, setting layout for the controller (with except also), just about everything published out there to no avail.</p> <p>What I'd really like to do is simply refresh the div with a partial without having the app layout being included. (Rails 3.2, Ruby 1.92)</p> <p>news controller:</p> <p>index.html.erb</p> <pre><code>&lt;div class="actions" id="refreshscribbles"&gt; &lt;%=render :partial=&gt; 'news/newsfeed', :locals=&gt;{:news=&gt;@news}%&gt; &lt;/div&gt; </code></pre> <p>_newsfeed.html.erb:</p> <pre><code>&lt;% news.each do |act| %&gt; &lt;%=render :partial=&gt; act["object_type"], :locals=&gt;{:activity=&gt;act}%&gt; &lt;br&gt;&lt;%= act["object_type"]%&gt; &lt;hr&gt; &lt;%end %&gt; </code></pre> <p>news.js (note, I've tried refreshnews in the url, etc, but it all just pulls back a page within a page at best).</p> <pre><code>$(document).ready(function(){ var timelyrefreshScribbleFeeds = function(){ url = '/news' $.get(url,function(data,status){ $('#refreshscribbles').html(data) return false }); }; setInterval(timelyrefreshScribbleFeeds,600); }); </code></pre> <p>news controller:</p> <pre><code>def refreshnews @news=News.get_newsstream(viewer_id, @per_page, @current_page) respond_to do |format| format.html #tried :layout =&gt; false, etc, to no avail format.json { render json: @news } end end </code></pre> <p>refreshnews.html.erb (empty - used to simply ignore no method error)</p> <p>routes.rb</p> <pre><code>get "refreshnews" =&gt; "news#refreshnews", :as =&gt; "refreshnews" </code></pre> <p>How would I refresh this div via ajax/jquery? I've seen multiple solutions but not one for rendering partials that render partials etc. What is wrong with the code / solution above?</p>
    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.
 

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