[英]How to get submit button value in form builder?
I'm creating a form using the simple_form
gem on Rails 3.2. 我正在Rails 3.2上使用simple_form
gem创建一个表单。
The problem I'm having is that I wish to add a font-awesome
icon to the f.button :submit
line of my form. 我遇到的问题是,我希望在f.button :submit
行中添加font-awesome
的font-awesome
图标。 Since the output is of type input
I can't embed the icon element inside of it. 由于输出是input
类型,因此无法将icon元素嵌入其中。
I could simply hardcode a submit
button into the form that contains the icon but I am not sure how to fetch the button value - Create %model
/ Update %model
. 我可以简单地将submit
按钮硬编码到包含图标的表单中,但是我不确定如何获取按钮值- Create %model
/ Update %model
。
My code is posted below: 我的代码发布在下面:
<div id="form">
<%= simple_form_for @program, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name %>
<%= f.input :url %>
<%= f.input :description, :input_html => { :class => "span5", :rows => 10 } %>
*********************
<%= f.button :submit do %>
<i class="icon-save"></i> What Here??? <--- Doesn't work since output is type input
<% end %>
*********************
<button class="btn">
<i class="icon-save"></i> <%= f.button(:submit).label %> <--- Doesn't work, alternative?
</button>
<% end %>
</div>
Expected output: 预期产量:
<button type="submit" class="btn">
<i class="icon-plus-sign"></i> Create *ModelName*
</button>
Or Update ModelName , depending on controller action. 或更新ModelName ,具体取决于控制器的操作。
<%= f.button do %>
<i class="icon-save"></i> <%= "#{f.object.new_record? ? 'Create' : 'Update'} #{f.object.class.model_name.human}" %>
<% end %>
It would be better to make some helper method for this. 为此,最好使用一些辅助方法。 If you want to use I18n take a look at source code ( button
and submit_default_value
methods, lines 1763 and 1776 ). 如果要使用I18n,请查看源代码 ( button
和submit_default_value
方法,第1763和1776行 )。 It's pretty clear. 很清楚
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.