This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= options_from_collection_for_select( | |
@products, | |
:id, | |
:name, | |
nil, # selected value(s) | |
lambda{|p| !p.in_stock? } # disabled value(s) identified with a proc | |
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= options_for_select( | |
['Choose a size', 'small', 'medium', 'large'], | |
nil, # selected value | |
'medium' # disabled value | |
) %> | |
<!-- Gives you --> | |
<option value="Choose a size">Please choose a size</option> | |
<option value="s">small</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= options_from_collection_for_select(@product.sizes, :name, :id, :disabled => lambda{|size| size.out_of_stock?}) %> | |
<!-- If small and medium returned true for the method out_of_stock?, you’d get something like: --> | |
<option value=“23“ disabled=“disabled“>small</option> | |
<option value=“24“ disabled=“disabled“>medium</option> | |
<option value=“25“>large</option> | |
<option value=“26“>extra large</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= select(:post, :category, Post::CATEGORIES, :disabled => 'private') %> | |
<!— Give's you something like —> | |
<select name="post[category]"> | |
<option>story</option> | |
<option>joke</option> | |
<option>poem</option> | |
<option disabled="disabled">private</option> | |
</select> |
NewerOlder