How to specify default value for a collection of associations?

4,463 views
Skip to first unread message

Alex Savin

unread,
Sep 3, 2011, 5:46:18 AM9/3/11
to SimpleForm
Hey, everyone

Is there any way to specify a default value for a list of
associations?

<%= f.association :bookmark, :collection =>
current_user.bookmarks(:order => :position), :include_blank => false
%>

How do I specify default value here?

Thanks!

Carlos Antonio

unread,
Sep 3, 2011, 8:00:45 AM9/3/11
to plataformate...@googlegroups.com
The selected value would be your "bookmark_id" attribute in the current form object. You can also give a :selected option that will be set as the selected item.

-- 
At.
Carlos Antonio

Alex Savin

unread,
Sep 4, 2011, 4:11:24 AM9/4/11
to SimpleForm
Thanks, that worked nicely!

-a

On Sep 3, 3:00 pm, Carlos Antonio <carlosantoniodasi...@gmail.com>
wrote:

Michel Pavan Macedo

unread,
Jul 11, 2012, 9:01:56 PM7/11/12
to plataformate...@googlegroups.com
Did you add something to make it work?

I am using Mongoid and I don't use :include_blank.

= f.input :column_name, collection: ModelName.all, value_method: :_id, label_method: :name

It lists all options correctly, update correctly, but don't select the current value automatically when I am editing.

Was it supposed to work? How would I make it work?

Michel Pavan Macedo

unread,
Jul 11, 2012, 10:08:25 PM7/11/12
to plataformate...@googlegroups.com
Never mind, I understood what you meant. :column_name is the :association_name_id, because it is input for collections, not associations.

--
Michel Pavan Macedo
Reply all
Reply to author
Forward
0 new messages