私は2つのクラスを持っており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'
これを行う方法?