Created
November 1, 2016 11:26
-
-
Save johnmeehan/d4a2f6c375f4106a6357cb8706dc2d4e to your computer and use it in GitHub Desktop.
Grouped Select Example
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
# :coffeescript | |
jQuery -> | |
designs = $('.design').html() | |
$('.style').change -> | |
style = $('.style option:selected').text() | |
options = $(designs).filter("optgroup[label='" + style + "']").html() | |
$('.design').html(options) |
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
-# scopes the designs based on the style choice. using simple_form grouped_select | |
.row | |
.col-md-3 | |
= f.input :style_id, collection: Style.glazed_panels.options_for_select, input_html: {class: 'form-control style'}, include_blank: false | |
.row | |
.col-md-3 | |
.form-group | |
-# = f.input(:design_id, collection: RenaissanceDesign.options_for_select, input_html: {class: 'form-control design'}, include_blank: false ) | |
= f.input :design_id, collection: Style.glazed_panels, as: :grouped_select, group_method: :designs, input_html: {class: 'form-control design'} |
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
# Models and associations. | |
class RenaissanceDesign < ActiveRecord::Base | |
belongs_to :style | |
end | |
class Style < ActiveRecord::Base | |
has_many :designs, class_name: 'RenaissanceDesign' | |
scope :glazed_panels, -> { where('......') } | |
scope :options_for_select, -> {order(:name).pluck(:name, :id)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment