Ruby on rails 如何将表单变量传递给页脚?

Ruby on rails 如何将表单变量传递给页脚?,ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我想将表单的=f.submit部分放在页脚部分中,但收到错误: 响应中的名称错误#新建 # 在下面的代码示例中,您会推荐哪些更改 app/views/layouts/application.html.haml app/views/layouts/_footer.html.haml 如果您想共享这样的元素,可以使用content\u for和yield,如下所示: # _footer.haml = yield :footer_content 然后在模板文件中: # new.haml = form

我想将表单的
=f.submit
部分放在页脚部分中,但收到错误:

响应中的名称错误#新建

#

在下面的代码示例中,您会推荐哪些更改

app/views/layouts/application.html.haml app/views/layouts/_footer.html.haml
如果您想共享这样的元素,可以使用
content\u for
yield
,如下所示:

# _footer.haml
= yield :footer_content
然后在模板文件中:

# new.haml
= form_for @object, id: 'form1' do |f|
  # form elements goes here

= content_for :footer_content do 
  %button{:onclick => "document.getElementById('form1').submit()"}
由于按钮位于表单外部,因此需要添加自定义JS才能正确提交表单


希望这有帮助。

为什么不使用
submit\u标签来代替呢?它将完成相同的任务。因此,如果您将submit按钮放在表单标记之外,那么它实际上不会提交表单。那么,您需要一些JS来提交表单。下面是我的答案。
= f.submit
# _footer.haml
= yield :footer_content
# new.haml
= form_for @object, id: 'form1' do |f|
  # form elements goes here

= content_for :footer_content do 
  %button{:onclick => "document.getElementById('form1').submit()"}