Search code examples
ruby-on-rails-3formtastic

Can not organize data in input collection


I have payment_type model with 3 elements saved. Also I have an order, where I want to store payment_type_id. I write in order view:
<%= f.input :pay_type_id, :as => :select, collection: PaymentType.names ...%>
But payment_type_id already saves as 0. As I understand, I'm trying to record payment_type.name instead of payment_type.id. What do I have to write in collection: to fix it?


Solution

  • <%= f.select :pay_type_id, PaymentType.all.collect {|x| [x.name, x.id]} %>
    

    This will display the name of the pay_type to the user in the dropdown, but submit the id of the pay_type to your form.