我有两个类Message
,Comment
关联如下
class Message ActiveRecord::Base
attr_accessible :comments_attributes
has_many :comments
accepts_nested_attributes_for :comments
end
class Comment ActiveRecord::Base
belongs_to :message
end
我将我的表格建模为
= form_for @message do |f|
f.text_field :msg
%a#add-comment Add Comment
_comment.html.haml
= f.fields_for :comments do |c|
c.text_field :value
单击“添加评论”按钮时,我通过 jquery 将评论输入附加到表单 f 中,如下所示
$('#add-comment').click(function() {
$('#add-comment').prepend(("#{escape_javascript(render(:partial => "comment", f: f))}");
});
但我无法访问此表单,我得到了
Undefined local variable or method 'f'
这个怎么做?