Simple Form, Rails and Bootstrap - problems with collections..

424 views
Skip to first unread message

Warren C

unread,
Aug 23, 2012, 11:33:59 AM8/23/12
to plataformate...@googlegroups.com
Hi - I'm a complete newbie.

I've used things like:-

<%= f.input :itemtype, label:"Item Type", :collection => [ "Active", "Assembly", "Cable", "Hardware" ], :prompt => "Select Type" %>

With great success, but when I try to pull the collection data from a table:-

<%= f.input :engineer, :collection => Engineer.all(:order => 'firstname'), :prompt => "Select Engineer" %>

I get the dropdown populated with a weird ID, rather than the firstname column which I need - I'm obviously missing something crucial.. help!

Vasiliy Ermolovich

unread,
Aug 23, 2012, 4:01:08 PM8/23/12
to plataformate...@googlegroups.com
Hi. If you want to use custom value or label methods for you collection input you can specify it as: 

<%= f.input :engineer, :collection => Engineer.all(:order => 'firstname'), :value_method => :firstname, :label_method => :firstname, :prompt => "Select Engineer" %>

You can read more about this options in the 'Collection' section of README file:  https://github.com/plataformatec/simple_form#collections

Warren C

unread,
Aug 23, 2012, 11:46:05 PM8/23/12
to plataformate...@googlegroups.com
Fantastic - that works perfectly.. and I will dig further into the documentation :-)
Reply all
Reply to author
Forward
0 new messages