0

所以我看过http://railscasts.com/episodes/43-ajax-with-rjs

但我有一个问题:

在我看来,我有以下几点:

<div id="testly">
    <%= render :partial => "test" %>
</div>

这行得通。

使用 create.rjs 更改此 div 中的内容,我的 create.rjs 文件中有以下内容:

page.replace_html :testly, :partial => 'test'

简单来说,这应该只是刷新部分吧?但它不起作用......希望有任何建议!


同样关于检查错误-我还不能(因为它在另一台计算机上),但是如果我将 create.rjs 中的 :partial => "test" 替换为 "..." 它只会替换它很好 - 让我相信这不是 ajax 的问题?


我做了更多的测试,部分声明有效 - 似乎不起作用的是通过 javascript 调用部分中的代码。

部分代码为:

<% today=Time.now.strftime("%m/%d/%Y") %>
<% @books.each do |book| %>
<% if book.created_at.strftime("%m/%d/%Y")==today %>
<div class="item-book" style="clear:both;">
    <%=h book.author.name %>
</div>
<div class="item-delete">
    <%= link_to '<div class="delete"></div>', book, :confirm => 'Are you sure?', :method => :delete %>  
</div>
<div class="item-date">
    <%=h book.created_at.strftime("%m/%d/%Y") %>    
</div>
<% end %>
<% end %>
4

1 回答 1

0

好的,现在,我已经解决了这个问题。

我制作了集合的部分部分(在视​​图中),并从部分中删除了循环。

然后在 create.rjs 中,我添加了 :bottom 和对象并将其更改为插入 html(如 Ryan 的视频中所见)。

这成功了。

于 2010-06-04T12:07:52.930 回答