gpt4 book ai didi

ruby-on-rails - = button_to如果已经采用其他形式,则不会生成形式

转载 作者:行者123 更新时间:2023-12-04 13:30:03 26 4
gpt4 key购买 nike

在我的情况下,新建和预览时都使用相同的局部创建和编辑形式。
部分看起来像这样(我使用HAML)

=form_tag ({:action => params[:action]},  :multipart => true)
=text_field :newsletter, :title
=text_area :newsletter, :body
=file_field :newsletter,:attachment
-if params[:action] == "preview"
=button_to "select contacts and send", :action => "contacts"
=submit_tag "save and preview"

但在html-output中是
...
<input type="submit" value="select contacts and send"/>
<input type="hidden" value="rwYnZlEpWV4dR89zjgprEALBYmP0xqM3lnKt9JDLyak=" name="authenticity_token"/>
<input type="submit" value="save and preview" name="commit"/>
...

为什么button_to不生成button-to表单?

一种解决方案是将按钮保留在部分表单的外部,每个表单仅保留1个按钮,
但是我怎么有两个相同形式的按钮?

编辑:
另一个解决方法将是由javascript设置的隐藏复选框,如果按下button_to并提交表单,则将其分隔在 Controller 中

最佳答案

HTML实际上不允许将表格嵌套。某些浏览器可以,但是其他浏览器会出现一些疯狂的行为。您显示的HTML是Firebug的原始输出还是计算出的DOM?

处理这种情况的首选方法是将button_to移到其他表单之外。如果您对仅使用JS的选项很满意,则可以使用link_to :method => :post并设置链接样式以使其看起来像一个按钮。

关于ruby-on-rails - = button_to如果已经采用其他形式,则不会生成形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1448688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com