如何使用rails和javascript一个提交按钮提交两个表单

我需要允许用户在要求他们提供帐户详细信息之前键入评论并提交。 提供这些详细信息后,它们将用于创建新用户,并且他们编写的注释也会提交并属于此新用户。 目前,我根本无法弄清楚如何在两个表单上触发提交操作,将所有信息传递给服务器以执行这些任务。

基本上我想要的是:

  • 用户撰写评论,提交
  • “提交”按钮显示联系信息表单
  • 用户填写此内容,提交
  • 提交两份表格的数据

是)我有的:

_feedback.html.erb

  false, :input_html => { :maxlength => '500', :rows => '4', :placeholder => '...'} %>        

show.html.erb

  
{ :multipart => true }, defaults: { label: false, required: true }) do |f| %> { :placeholder => 'Your Name', :id => 'name'} %> { :placeholder => 'Your Email', :id => 'email'} %>

posts.js

 function contactDisplay(){ var contact = document.getElementById('contact'); contact.style.display='block'; } function submitContact(){ document.getElementById("new_comment").submit(); document.getElementById("new_user").submit(); } 

您可以使用嵌套表格:)以下是有关如何操作的railscast http://railscasts.com/episodes/196-nested-model-form-part-1