Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 simple_form collection_select

How do I translate the following to simple form?

<%= form_for(@bill) do |f| %>  <%= f.label :location_id %> <%= f.collection_select(:location_id, @locations, :id, :location_name,        {:selected => @bill.location_id}) %> 

I can't use a simple association because @locations is the result of a where query.

like image 321
markhorrocks Avatar asked Jul 17 '13 14:07

markhorrocks


1 Answers

Try this

<%= simple_form_for @bill do |f| %>    <%= f.input :location,:collection => @locations,:label_method => :location_name,:value_method => :id,:label => "Location" ,:include_blank => false %>    <%= f.button :submit %> <%end%> 

Hope this help

like image 127
Viren Avatar answered Oct 08 '22 22:10

Viren