【问题标题】:`button_tag` instead of `submit_tag``button_tag` 而不是 `submit_tag`
【发布时间】:2015-08-03 12:16:52
【问题描述】:

我想在我的表单提交按钮中包含一个字形图标。 submit_tag 中不能包含字形图标,所以我使用了button_tag

但是,在某些表单中,我有不同的 submit_buttons(例如 preview|for_real),我使用了:

button "commit"

控制器中的消息以执行特定操作:

if params[:commit] == 'Preview'

仅适用于submit_tag

1。我想了解两者之间的区别。

导轨submit_tag

submit_tag "Edit this article"
# => <input name="commit" type="submit" value="Edit this article" />

button_for

<%= button_tag(type: "submit", class: "btn btn-default") do %>
    Edit this article <i class="icon-repeat"></i>
<% end %>

区别仅仅是input 也会提交一个不允许 HTML/glyphicons 的提交消息吗?

2。有一个带有字形图标的submit_tag 行为(提交消息)的解决方法是什么?

或者不建议使用commit 值,而应该使用可以与button_tag 一起使用的其他值?

【问题讨论】:

    标签: ruby-on-rails html ruby-on-rails-4


    【解决方案1】:

    解决方法是button_tag的解决方案其实没有问题。因此submit_tag 毫无用处(直到我发现它比 button_tag 有其他一些优势)。

    button_tag(name: 'commit', type: 'submit', value: 'Edit this article')
    button_tag(name: 'commit', type: 'submit', value: 'Publish')
    

    虽然它们在 HTML 中都呈现为&lt;button&gt;,但只有被点击的那个值会被传递!

    【讨论】:

      猜你喜欢
      • 2017-02-21
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多