Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Guilded Rails component that generates a select box and connects it to a parent select box to facilitate a parent child relationship.
Ruby JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails_generators/nested_select_assets
script
spec
tasks
History.txt
Manifest.txt
PostInstall.txt
README.rdoc
Rakefile
g_nested_select.gemspec

README.rdoc

g_auto_completer

github.com/midas/g_nested_select/tree/master

DESCRIPTION:

A Guilded (github.com/midas/guilded/tree/master) Rails component that generates a select box and connects it to a parent select box to facilitate a parent child relationship.

FEATURES:

INSTALL:

sudo gem install midas-g_nested_select

In rails environment.rb file:

config.gem 'midas-g_nested_select', :version => "1.0.1", :lib => 'g_nested_select', :source => 'http://gems.github.com'

Generate:

script/generate nested_select_assets

USAGE:

<% form_for @car do |f| %>
  ...

  <%= f.select :vehicle_make_id, VehicleMake.to_select_collection, :id => 'car_vehicle_make_id' %>

  <%= g_nested_select f, :vehicle_model_id, :mappings => VehicleModel.to_select_collection, :include_blank => true, 
        :parent_id => 'car_vehicle_make_id', :mapping_type => :html 
<% end %>

Where VehicleModel.to_select_collection returns either:

[
  ['Toyota', [['Camry',1],['Corola',2]]], ['Volvo', [['S40',3],['S60',4]]]
]

or

{
  'Toyota' => [['Camry',1],['Corola',2]], 'Volvo' => [['S40',3],['S60',4]]
}

When JavaScript is disabled, the above will result in:

<select id="ticket_vehicle_model_id" name="ticket[vehicle_model_id]">
  <option value=""/>
  <optgroup label="Toyota">
    <option value="1">Camry</option>
    <option value="2">Corola</option>
  </optgroup>
  <optgroup label="Volvo">
    <option value="3">S40</option>
    <option value="4">S60</option>
  </optgroup>
</select>

When JavaScript is enabled the vehicle model id select control will be loaded with the vehicle models that are related to what is currently selected in the vehicle make id select box. If there is nothing selected yet, then the vehicle model id select box will be empty and will not populate until the vehicle make is selected.

If you open an edit view and there is already a value selected for both the vehicle make and vehicle model the vehicle model selection will automatically select the correct value once it has loaded the nested options.

OPTIONS:

  • :mappings (required) - A collection suitable for creating a nested drop down (see example usage above for details).

  • :include_blank - When true, includes an empty option at top of select box, otherwise does not. Defaults to false.

  • :parent_id (required) - The id of the parent select box that the nested select box's values will be loaded based on.

  • :mapping_type - :lookup for JavaScipt to generate the HTML from the lookup object that comes over form the server.

    :html for the server to generate the html server side and send it over.  Defaults to :lookup.

REQUIREMENTS:

LICENSE:

(The MIT License)

Copyright © 2009 C. Jason Harrelson (midas)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.