Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用Rails表单助手生成按钮元素而不是输入元素_Html_Ruby On Rails_Form Helpers - Fatal编程技术网

Html 使用Rails表单助手生成按钮元素而不是输入元素

Html 使用Rails表单助手生成按钮元素而不是输入元素,html,ruby-on-rails,form-helpers,Html,Ruby On Rails,Form Helpers,在我的Rails应用程序中,我使用了一个前端模板,通过从标记中选择按钮来使用CSS设置按钮样式 问题是Rails表单帮助程序通过生成带有标记而不是标记的HTML代码来呈现按钮。因此,在执行以下html.erb代码时: <%= simple_form_for @waiter do |f| %> <%= f.input_field :email %> <%= f.button :submit, "My button" %> <% end %&

在我的Rails应用程序中,我使用了一个前端模板,通过从标记中选择按钮来使用CSS设置按钮样式

问题是Rails表单帮助程序通过生成带有标记而不是标记的HTML代码来呈现按钮。因此,在执行以下html.erb代码时:

<%= simple_form_for @waiter do |f| %>
    <%= f.input_field :email %>
    <%= f.button :submit, "My button" %>
<% end %>

它将按钮呈现为:

<input type="submit" name="commit" value="My button" class="btn btn-default" data-disable-with="My button">   

我想为按钮生成一个HTML代码,类似于:

<button relevant_attributes="relevant values">My button</button>  
我的按钮
到目前为止,我一直在尝试,但没有成功:

  • 将CSS id添加到输入标记并修改模板样式表以复制按钮样式(我意识到这不是一个有效的选项,原因很难在这里解释)
  • 使用vanilla Rails表单帮助程序而不是表单帮助程序(同时呈现输入标记元素)
  • 到目前为止,唯一的解决方案是直接创建HTML按钮元素(如下所示),并将其绑定到onClick JS事件,该事件触发通过JS提交表单的Ajax请求:

    <%= simple_form_for @waiter do |f| %>
        <%= f.input_field :email %>
        <button id="my-button">My button</button>
    <% end %>
    
    
    我的纽扣
    
    目前的解决方案似乎不是很优雅。有谁能给我一个更好的建议吗?是否可以通过Rails助手生成按钮元素

    您可以使用

    默认情况下,提交表单应该是
    type=“submit”