在Rails中重新渲染重新加载部分

时间:2022-04-01 16:17:40

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. Lightbox information is NOT updated with the changes the user just made.

3.)用户再次单击链接重新打开灯箱。灯箱信息不会根据用户刚刚进行的更改进行更新。

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:

    <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.

我如何获得部分重新渲染,这意味着从数据库中提取新信息(检查它是否被收藏,新评论等)每次点击链接?我的当前链接似乎只是缓存旧信息,直到页面刷新。

1 个解决方案

#1


0  

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.

信息是否保存在数据库中?如果是这样,那么主页面将包含该行的一些信息,然后它可能会在表格中发生变化,请在执行代码时检查所有步骤。

#1


0  

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.

信息是否保存在数据库中?如果是这样,那么主页面将包含该行的一些信息,然后它可能会在表格中发生变化,请在执行代码时检查所有步骤。