2012-11-13 67 views
4

我想在我的表单中使用简单的形式+ bootstrap创建一个元素。这个想法是让用户从下拉菜单中选择一种货币类型。选择元素,simple_form帮助

Customer_currency可以选择美元美元,LRD - 利比里亚元等。

我用我的形式下

但是,它不工作,我看到的是一个下拉(出位)在我的形式与选项,但没有标签。

如何创建一个标签一个很好的选择元素用简单的形式

<%= simple_form_for @customer, :html => { :class => 'form-horizontal' } do |f| %> 
<%= f.input :name %> 
<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %> 
<%= f.input :payment_terms %> 
<%= f.input :billing_address %> 
<%= f.input :first_name %> 
<%= f.input :last_name %> 
<%= f.input :mobile %> 
<%= f.input :email %> 
<div class="form-actions"> 
<%= f.button :submit, :class => 'btn-primary' %> 
<%= link_to t('.cancel', :default => t("helpers.links.cancel")), 
      customers_path, :class => 'btn' %> 
</div> 
<% end %> 
+0

增加了它在这个问题 – zurik

+0

试试我的回答,我张贴。 – Thanh

+0

由于某种原因,它仍然没有显示标签 – zurik

回答

0

添加label_methodvalue_method你的选择,意味着变化:

<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %> 

到:

<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]], label_method: :first, value_method: :last %> 

更新:其他解决方案

<%= f.input :customer_currency, as: :select, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]], label_method: :first, value_method: :last %> 
+0

嘿,这个更新也不起作用,但是这个做了<%= f.input:customer_currency,:collection => [['UGX-Uganda Shillings',1],['USD- US Dollars',2]] %> – zurik

+0

@zurik好的,所以请张贴您的答案并接受它。 – Thanh

8
<%= f.input :customer_currency, :collection => [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %> 
+1

这是以简单形式执行此操作的正确方法 –