我在我的RoR应用程序中得到以下错误: RJS error:
TypeError:元素为空
Element.update(“通知”,“发布的评论”);Element.update(“所有评论”,“\n\n现在做什么?\n\n
\n");
但当我点击刷新按钮时,我可以看到我的部分更新。
下面是我的代码:
show_comments视图:
<table>
<% comments.each do |my_comment| %>
<tr>
<td><%=h my_comment.comment%></td>
</tr>
<% end %>
</table>显示视图:
<div class="wrapper">
<div class="rescale">
<div class="img-main">
<%= image_tag @deal.photo.url %>
</div>
</div>
<div class="description">
<p class ="description_content">
<%=h @deal.description %>
</p>
</div>
</div>
<p>
<b>Category:</b>
<%=h @deal.category %>
</p>
<p>
<b>Base price:</b>
<%=h @deal.base_price %>
</p>
<%#*<p>%>
<%#*<b>Discount:</b>%>
<%#=h @deal.discount %>
<%#*</p>%>
<%= link_to 'Edit', edit_deal_path(@deal) %> |
<%= link_to 'Back', deals_path %>
<p>
<%= render :partial=>'deal_comments', :locals=>{
:comments=>Comment.new(:deal_id=>@deal.id)} %>
</p>
<div id="allcomments">
<%= render :partial=>'show_comments', :locals=>{
:comments=>Comment.find(@deal.comments)} %>
</div>控制器:
def create
@comment = Comment.new(params[:comment])
render :update do |page|
if @comment.save
page.replace_html 'notice', 'Comment Posted'
else
page.replace_html 'notice', 'Something went wrong'
end
page.replace_html 'allcomments', :partial=> 'deals/show_comments',
:locals=>{:comments=> @comment.deal.comments}
end
end
def show_comments
@deal = Deal.find(params[:deal_id])
render :partial=> "deals/show_comments", :locals=>{:comments=>@deal.comments}
end
end发布于 2011-01-03 21:51:20
我看不到ID为'notice‘的DOM元素-我是不是遗漏了什么?我假设您确实有一个具有该ID的元素,否则,是的,您将得到一个空异常。
https://stackoverflow.com/questions/4584021
复制相似问题