简体   繁体   中英

Re-rendering Reloading Partial in Rails

I have a list of links to posts on a page. When clicked, the link triggers a lightbox with a partial showing the post.

My problem:

1.) A user interacts with the lightbox and changes information about the post (favoriting, unfavoriting).

2.) User then closes the lightbox

3.) User reopens the lightbox by clicking on the link again. Lightbox information is NOT updated with the changes the user just made.

4.) But if the user refreshes the whole page Ctrl+R and clicks on the lightbox, the lightbox will reflect the new changes.

Lightbox I am using is FancyBox.

Link to Lightbox

     <a class="fancyboxentry" rel="entries" href="#entryshow<%= thispost.id%>" onclick ="renderEntry<%=thispost.id%>()">
     <%= image_tag(thispost.content_2)%>
     </a>

Dummy div to hold loaded partial.

     <div id="entryshow<%= thispost.id %>"> </div>

renderEntry function:

    <script>
    function renderEntry<%= thispost.id%>() {
    $('#entryshow<%= thispost.id%>').html("<%=escape_javascript(render(:partial => 'posts/show', :locals => {:id => thispost.id})).html_safe %>");}
    </script>

How can I get the partial to re-render, which means pulling new information from the database (checking whether it is favorited, new comments, etc) EVERY time the link is clicked? My current links seem to just cache old information until the page is refreshed.

whether the information is saved in database ? if so then main page will have some information for that row ,then again it may changing in the table, please inspect all the steps while executing the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM