Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9110: form_options_helper_select_doc.diff

File form_options_helper_select_doc.diff, 3.9 kB (added by priit, 1 year ago)
  • vendor/rails/actionpack/lib/action_view/helpers/form_options_helper.rb

    old new  
    5656    module FormOptionsHelper 
    5757      include ERB::Util 
    5858 
    59       # Create a select tag and a series of contained option tags for the provided object and method. 
    60       # The option currently held by the object will be selected, provided that the object is available. 
    61       # See options_for_select for the required format of the choices parameter. 
     59      # Return select and option tags for the given object and method. 
    6260      # 
    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      #  
    6473      #   select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, { :include_blank => true }) 
    6574      # 
    66       # could become: 
     75      # could become:  
    6776      # 
    6877      #   <select name="post[person_id]"> 
    6978      #     <option value=""></option> 
     
    7180      #     <option value="2">Sam</option> 
    7281      #     <option value="3">Tobias</option> 
    7382      #   </select> 
     83      #  
     84      # Return a drop down select box of names where Sam is selected or prompts 'Select Person' when @post.person_id is not available 
    7485      # 
    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'}) 
    8087      # 
    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. 
    8399      def select(object, method, choices, options = {}, html_options = {}) 
    84100        InstanceTag.new(object, method, self, nil, options.delete(:object)).to_select_tag(choices, options, html_options) 
    85101      end