当我的create.js.erb执行时,我的firebug响应中出现错误。请参阅下文。
<% if @document.new_record? %>
alert("Failed to upload document: <%= j @document.errors.full_messages.join(', ').html_safe %>");
<% else %>
$('#documents').append("<%= j render(:partial => "home/document", :document => @document) %>");
<% end %>
NameError at /documents
=======================
> undefined local variable or method `document' for #<#<Class:0x08d11700f0>:0x007f8dcb9bfc20>
app/views/home/_document.html.erb, line 2
-----------------------------------------
``` ruby
1 <tr class="document_details file">
> 2 <td class="file_name"><%= link_to document.name, download_url(document) %></td>
3 <td class="file_size"><%= number_to_human_size(document.file_size, :precision => 2) %></td>
4 <td class="file_last_updated"><%= document.file_updated_at %></td>
5 <td class="actions">
6 <div class="download">
7 <%= link_to "Download", download_url(document) %>
```
答案 0 :(得分:1)
而不是
render(:partial => "home/document", :document => @document)
你应该:
render(:partial => "home/document", :locals => {:document => @document})