GarciadelCastillo
GarciadelCastillo

Reputation: 426

Rails - Simple Form - Force a non-multiple select input field

I am creating an input form for a Post model with Simple Form on a Rails app. The Post model is associated to a Keyword model with a has_and_belongs_to_many. To fill up the Tags in the form, I am using:

<%= f.association :keywords, collection: Keyword.all(order: 'name'), prompt: "Select keyword..." %>

which creates a html :select tag for the input. The problem is, because is a many to many association, Simple Form assigns the :multiple tag to :select by default, allowing selecting many objects. But I do want to force it to output a simple <select> with no multiple for this field.

Any idea how to do this? Thanks a lot!

Upvotes: 0

Views: 1531

Answers (1)

GarciadelCastillo
GarciadelCastillo

Reputation: 426

Figured it out, pass :input_html => { :multiple => false }

<%= f.association :keywords, collection: Keyword.all(order: 'name'), prompt: "Select keyword...", :input_html => { :multiple => false } %>

Upvotes: 1

Related Questions