简体   繁体   English

重新渲染Rails中的部分重载

[英]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). 1.)用户与灯箱进行交互,并更改有关帖子的信息(收藏夹,收藏夹)。

2.) User then closes the lightbox 2.)然后,用户关闭灯箱

3.) User reopens the lightbox by clicking on the link again. 3.)用户通过再次单击链接来重新打开灯箱。 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. 4.)但是,如果用户刷新整个页面Ctrl + R并单击灯箱,则灯箱将反映新的更改。

Lightbox I am using is FancyBox. 我使用的灯箱是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可容纳部分加载。

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

renderEntry function: renderEntry函数:

    <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. 如果是这样,则主页将具有该行的某些信息,然后表中的行可能会再次更改,请在执行代码时检查所有步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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