这是我的评论/ _form.html.erb
中的代码段<%#
Create/edit a single comment
render :partial => "comment/form",
:locals => {:comment => my_comment, :stage => my_stage, :user => my_user }
%>
<%
comment ||= Comment.new
comment.stage = stage
comment.user = user
new_record = comment.new_record?
%>
<%= form_for(comment, :html => { :class=>"ajax-form", :id => "comment-ajax-form"}, :remote => true, :disable_with => (new_record ? "Adding..." : "Saving...")) do |f| %>
<%= f.hidden_field :stage_id %>
<%= f.hidden_field :user_id %>
<h3>Add a Comment</h3>
<% if comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<div class="uploads" >
<div class="hint">Select the images you are discussing</div>
<% stage.uploads.each do |upload| %>
<div class="upload-image image-selector" title="<%= upload.name %>" id="image-selector-<%= upload.id %>">
<%= image_tag upload.image.url(:thumb) %>
<%= check_box_tag "comment[upload_ids][]", upload.id, comment.uploads.include?(upload), :id => "comment[uploads_ids][#{upload.id}]", :autocomplete => "off", :style => "display:none;" %>
</div>
<% end %>
</div>
<%= f.text_area :body, :style=> "width: 100%", :rows => 10 %>
<div class="actions">
<%= f.submit(new_record ? "Add Comment" : "Save", :class => "green awesome") %>
</div>
</div>
<br style="clear:both" />
<% end %>
<% content_for(:deferred_js) do %>
$('#comment-ajax-form')
.bind("ajax:success", function(evt, data, status, xhr){
compv.comments.updateView('comments', xhr);
$('div.image-selector').each(function(){
var element = $(this);
element.children('input').attr('checked', false);
element.removeClass('selected-image');
});
});
// Code will also need to be changed in the #add-comment click event in view.js
$('div.image-selector').live("click", function(){
var element = $(this);
var checkbox = element.children('input');
if(!checkbox.attr('checked')){
checkbox.attr('checked', true);
element.addClass('selected-image');
}else{
checkbox.attr('checked', false);
element.removeClass('selected-image');
}
});
<% end %>
它产生的错误是在第9行附近 - 即comment.stage = stage:
undefined local variable or method `stage' for #<#<Class:0x00000105621a50>:0x0000010561d450>
当我访问myapp.com/comments/2/edit
时,我看到了这个错误编辑视图只执行以下操作:
<h3> Editing a Comment </h3>
<%= render 'form' %>
<%= link_to 'Show', @comment %>
但是,当我转到一个呈现此表单的页面时,我添加了一个新评论,这很好。它不会产生此错误。
刚才我正在尝试编辑和删除产生此错误的所述评论。
想法?