有没有一种方式与铁路形式助手产生一个按钮标签提交 [英] Is there a way with rails form helper to produce a button tag for submit
问题描述
我正在尝试创建按钮ala Wufoo(重新发现按钮元素 )
我想写下如下代码:
<%form_tag search_path,:method => :get,:class => 'search'do%>
<%= text_field_tag:search,params [:search] - %>
<%= button_tag'search',:name =>零 - %GT;
<%end%>
生成以下HTML(而不是输入[type =submit] tag) p>
< button type =submitclass =positive>
< img src =/ images / icons / tick.pngalt =/>
保存
< /按钮>
方法已经存在吗?或者我应该推出自己的帮手?
您可以使用content_tag来实现此目的。这是做你想做的更有道理的方式。但它比原始HTML长。
<%content_tag:button:type => :submit,:class => :正面做%>
<%= image_tag图标/ tick.png%>
保存
<%end%>
其中产生
< button type =submitclass =positive>
< img src =/ images / icons / tick.pngalt =Tick/>
保存
< /按钮>
然而,以此为出发点,您应该没有问题自己动手使用强大的助手,或者将其抽象化到部分。
I am trying to create buttons ala Wufoo (Rediscovering the button element)
I would like to write the following code like the following:
<%form_tag search_path, :method => :get, :class => 'search' do %>
<%=text_field_tag :search, params[:search] -%>
<%=button_tag 'search', :name => nil-%>
<%end%>
To generate the following HTML (instead of the input[type="submit"] tag)
<button type="submit" class="positive">
<img src="/images/icons/tick.png" alt=""/>
Save
</button>
Does a method exist already? Or should I roll my own helper?
You could use content_tag to achieve this. It's the more railsy way of doing what you want. But it's longer than the raw HTML.
<% content_tag :button :type => :submit, :class => :positive do %>
<%= image_tag "icons/tick.png"%>
Save
<% end %>
Which produces
<button type="submit" class="positive">
<img src="/images/icons/tick.png" alt="Tick"/>
Save
</button>
However using this as a starting point you should have no problem rolling your own robust helper, or abstracting it to a partial.
这篇关于有没有一种方式与铁路形式助手产生一个按钮标签提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!