Select element, simple_form helper

I am trying to create an element in my form that uses a simple + bootstrap form. The idea is to let the user select a currency type from the drop-down list.

Customer_currency for choosing from USD-US Dollars, LRD - Liberian dollar among others.

I used the following in my form

However, it does not work, all I see is a dropdown (out of position) in my form with parameters, but without a label.

How to create a nice select element with a label using a simple form

<%= 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 %> 
+4
source share
2 answers
 <%= f.input :customer_currency, :collection => [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %> 
+8
source

Add label_method and value_method to your selection, this means a change:

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

in

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

Update: another solution

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

Source: https://habr.com/ru/post/1445712/


All Articles