Skip to content

Simple helper method to generate a list of select box options with HTML attributes

Notifications You must be signed in to change notification settings

ddonahue99/options_for_select_with_attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

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

About

Simple helper method to generate a list of select box options with HTML attributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages