| 63 | | # Example with @post.person_id => 1: |
|---|
| | 61 | # ==== Options |
|---|
| | 62 | # <tt>:include_blank</tt>:: Set to true or a prompt string if the first option element of the select element is a blank. |
|---|
| | 63 | # Useful if there is not a default value required for the select element. |
|---|
| | 64 | # <tt>:prompt</tt>:: Set to true or a prompt string. When the select element doesn't have a value yet, |
|---|
| | 65 | # this prepends an option with a generic prompt -- "Please select" -- or the given prompt string. |
|---|
| | 66 | # <tt>:selected</tt>:: Set to nil to leave all options unselected or a value to use a different selection. |
|---|
| | 67 | # By default, selected option will be currently available object. |
|---|
| | 68 | # See options_for_select for the required format of the choices parameter. |
|---|
| | 69 | # |
|---|
| | 70 | # ==== Examples |
|---|
| | 71 | # Return a drop down select box of names where David is selected when @post.person_id # => 1 |
|---|
| | 72 | # |
|---|
| 75 | | # This can be used to provide a default set of options in the standard way: before rendering the create form, a |
|---|
| 76 | | # new model instance is assigned the default options and bound to @model_name. Usually this model is not saved |
|---|
| 77 | | # to the database. Instead, a second model object is created when the create request is received. |
|---|
| 78 | | # This allows the user to submit a form page more than once with the expected results of creating multiple records. |
|---|
| 79 | | # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. |
|---|
| | 86 | # select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, {:prompt => 'Select Person', :include_blank => 'None'}) |
|---|
| 81 | | # By default, post.person_id is the selected option. Specify :selected => value to use a different selection |
|---|
| 82 | | # or :selected => nil to leave all options unselected. |
|---|
| | 88 | # could become (when @post.person_id # => 2): |
|---|
| | 89 | # |
|---|
| | 90 | # <select name="post[person_id]"> |
|---|
| | 91 | # <option value="">Select Person</option> |
|---|
| | 92 | # <option value="">None</option> |
|---|
| | 93 | # <option value="1">David</option> |
|---|
| | 94 | # <option value="2" selected="selected">Sam</option> |
|---|
| | 95 | # <option value="3">Tobias</option> |
|---|
| | 96 | # </select> |
|---|
| | 97 | # |
|---|
| | 98 | # NOTE: When manually testing be aware some browsers keep remembering selected value even after you do refresh, be sure to reload your page completely. |
|---|