This controller object stores two Rubyarrays in the variablesindArrandteamArr (these values could alternatively be generated from a database). Remember the web page’s existingselectlist that gives the user a choice of Team or Individual? This is aselectelement with thename categories. The browser submits this value as a form parameter to the Rails action. The code uses the syntaxparams[:categories] to get this parameter’s value. Then things get interesting, in a Rails kind of way. The server still has to provide an HTTP response to the Ajax request object.
The action uses the RoRrender()method to send the HTML for aselectlist back to our application, with thearrayvalues as theselect list contents:
render()specifies in its first parameter apartialnamedoptions. In Rails lingo, apartialis just a template that contains a chunk of content that can be used over and over again—for example, one or a few HTML tags. Using the Rails naming convention, thepartial(really a text file) is placed in the app/ views/hacks directory with its name preceded by an underscore, as in _options. rhtml. So, in plain English, the method call declares, “Render the response as the_options partialcontent, and hand thepartialtwo local variables,:sportsand:sptype.”