Ruby on rails 轨道。如何通过javascript和Jquery使用form builder对象

Ruby on rails 轨道。如何通过javascript和Jquery使用form builder对象,ruby-on-rails,ajax,nested-forms,Ruby On Rails,Ajax,Nested Forms,我已经阅读这个论坛三天了,所以我敢问我的问题:- 我有一个 <%= form_for(@post) do |f| %> which builds a @post. 添加注释,新注释文本与 new_object = f.object.class.reflect_on_association(:comments).klass.new 这将适用于经典的link_to或submit call 但我的问题是我需要通过AJAX调用传递f对象 事实上,我的嵌套注释将同时保存。因此,我需要处理

我已经阅读这个论坛三天了,所以我敢问我的问题:-

我有一个

<%= form_for(@post)  do |f| %> which builds a @post.
添加注释,新注释文本与

new_object = f.object.class.reflect_on_association(:comments).klass.new
这将适用于经典的link_to或submit call

但我的问题是我需要通过AJAX调用传递f对象

事实上,我的嵌套注释将同时保存。因此,我需要处理具有嵌套属性的未保存对象,无法预测注释的数量

我的控制器如下所示:

def new
    @post = Post.new()
end 

def add_comment(f, new_comment_text)
    new_object = f.object.class.reflect_on_association(:comments).klass.new
    and much more...to render a partial of build comments...
end
总而言之,我想:

@post=post.new在posts\U控制器中-没有问题

造形_for@post在我的新观点中,做f——没问题

使用已存在的注释列表在表单内部生成一个分部 这是评论文本,点击这个AJAX链接可以破坏它…更棘手

调用add_commentf,new_comment_text函数,引用f对象向@post现有但未保存的添加注释-如何通过ajax将引用传递给它?。要求此函数

那么有没有可能 @post=功能1中的post.new 并从function2访问此对象@post,即使它尚未保存在数据库中?功能1和功能2位于同一控制器中

有什么想法吗

厚度单位:-

new_object = f.object.class.reflect_on_association(:comments).klass.new
def new
    @post = Post.new()
end 

def add_comment(f, new_comment_text)
    new_object = f.object.class.reflect_on_association(:comments).klass.new
    and much more...to render a partial of build comments...
end
@comment = @post.comments.build     
(or @comment = f.object.class.reflect_on_association(:comments).klass.new ??)
@comment.comment_text = new_comment_text
render a partial with @post.comments.all