Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 732 Bytes

README.rdoc

File metadata and controls

15 lines (11 loc) · 732 Bytes

options_for_select_with_attributes

Usage

Works just like options_from_collection_for_select but allows you to pass in a hash of HTML attributes and methods.

options_for_select_with_attributes(collection, value, label, attributes, selected=nil)

Example

form.select :user_id, options_for_select_with_attributes(User.all, :id, :name, { :class => :role }, current_user)

This will yield options with the class attribute set to user.role:

<option value="1" class="president" selected="selected">George Washington</option>
<option value="16" class="president">Abraham Lincoln</option>

See Also

api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_from_collection_for_select