【发布时间】:2018-02-18 05:15:49
【问题描述】:
我想将表单的 = f.submit 部分放在页脚部分中,但出现错误:
响应中的名称错误#new
#<#Class<Class:0x00007fcd80439d10>:0x00007fcd804314d0>的未定义局部变量或方法“f”
您会建议我在下面的代码示例中进行哪些更改?
app/views/layouts/application.html.haml
%body
%main
= yield
%footer
= render partial: 'layouts/footer', locals: { f: f } # <-- this line errors
app/views/responses/new.html.haml
= form_for @response do |f|
= f.text_field :answer
app/views/layouts/_footer.html.haml
= f.submit
【问题讨论】:
-
你为什么不改用
submit_tag呢?它会完成同样的事情 -
另外,如果您将提交按钮放在表单标签之外,那么它实际上不会提交表单。那么,您将需要一些 JS 来为您提交表单。请参阅下面的答案。
标签: ruby-on-rails ruby-on-rails-5