所以我看过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 %>