Skip to content

Instantly share code, notes, and snippets.

@manfe
Created September 11, 2012 20:24

Revisions

  1. manfe revised this gist Sep 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _some_field.html.haml
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    = f.association :cities, :collection => State.all, :as => :grouped_select,
    :group_method => :cities, :group_label_method => :name
    :group_method => :cities, :group_label_method => :name
  2. manfe revised this gist Sep 11, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion _some_field.html.haml
    Original file line number Diff line number Diff line change
    @@ -1 +1,2 @@
    = f.association :cities, :collection => State.all, :as => :grouped_select, :group_method => :cities, :group_label_method => :name
    = f.association :cities, :collection => State.all, :as => :grouped_select,
    :group_method => :cities, :group_label_method => :name
  3. manfe revised this gist Sep 11, 2012. 2 changed files with 2 additions and 4 deletions.
    4 changes: 1 addition & 3 deletions _some_field.html.haml
    Original file line number Diff line number Diff line change
    @@ -1,3 +1 @@
    = f.association :cities, :collection => State.all, :as => :grouped_select, :group_method => :cities, :group_label_method => :name


    = f.association :cities, :collection => State.all, :as => :grouped_select, :group_method => :cities, :group_label_method => :name
    2 changes: 1 addition & 1 deletion city.rb
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,4 @@ class City < ActiveRecord::Base
    validates :name, :presence => true

    belongs_to :state
    end
    end
  4. manfe revised this gist Sep 11, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion state.rb
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,4 @@ class State < ActiveRecord::Base
    validates :name, :presence => true

    has_many :cities, :order => :name #this order will show the cities in alphabetical order inside each optgroup

    end
  5. manfe created this gist Sep 11, 2012.
    3 changes: 3 additions & 0 deletions _some_field.html.haml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    = f.association :cities, :collection => State.all, :as => :grouped_select, :group_method => :cities, :group_label_method => :name


    6 changes: 6 additions & 0 deletions city.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    class City < ActiveRecord::Base
    attr_accessible :name
    validates :name, :presence => true

    belongs_to :state
    end
    7 changes: 7 additions & 0 deletions state.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    class State < ActiveRecord::Base
    attr_accesible :name
    validates :name, :presence => true

    has_many :cities, :order => :name #this order will show the cities in alphabetical order inside each optgroup

    end