我正在尝试制作一个类似于Reddit的线索评论系统:我在评论上单击“回复”,表单显示出来。该表单有一个“取消”按钮,用于删除表单,返回原始状态。使用Rail的原型助手形式显示/隐藏效果
我试图用一个link_to_function
添加表单,并且表单本身有一个button_to_function
来删除自己和表单。所以由link_to_function
生成的javascript需要逃过HTML 与逃脱它的JavaScript,由于某种原因,它不工作(点击“回复”没有做任何事情)。如果我不添加“取消”按钮,它工作正常。下面是我有:
<!-- comments/_comment.html.erb -->
<div id="comment_<%= comment.id %>">
<%= h comment.content %>
</div>
<div id="reply_comment_<%= comment.id %>"></div>
<%= link_to_function 'Reply' do |page|
page.replace_html "reply_comment_#{comment.id}",
render(:partial => 'comments/form', :locals => {:comment => comment,
:commentable => comment.commentable})
end
%>
和:
<!-- comments/_form.html.erb -->
<% form_tag(comments_path) do %>
<%= hidden_field_tag 'comment[parent_id]', comment && comment.id %>
<%= hidden_field_tag 'comment[commentable_id]', commentable.id %>
<p>
<%= text_area_tag 'comment[content]' %>
</p>
<p>
<%= submit_tag 'Send' %>
<% if comment %>
<%= button_to_function 'Cancel' do |page|
page.replace_html "reply_comment_#{comment.id}", ''
end
%>
<% end %>
</p>
<% end %>
我在做什么错?