ruby - grouped collection select in rails -


i'm in stages of developing dynamic drop-down menu signup form.

i have 4 models.

city has_many :burroughs has_many :hoods  burrough belongs_to :city has_many :hoods  hood belongs_to :city belongs_to :burrough  user belongs_to :city belongs_to :burrough (this can nil, or needs able nil) belongs_to :hood 

my goal create dropdown-select. nyc (city) divided burroughs (ie brooklyn) divided hoods (ie. park slope, williamsburg).

for city, skip burrough , go straight city (boston) hood (cambridge) although i'm not quite far yet.

here tables

create_table "hoods", force: true |t| t.string   "name" t.integer  "burrough_id" t.datetime "created_at" t.datetime "updated_at" t.integer  "city_id" end  create_table "burroughs", force: true |t| t.string   "name" t.integer  "city_id" t.datetime "created_at" t.datetime "updated_at" end  create_table "cities", force: true |t| t.datetime "created_at" t.datetime "updated_at" t.string   "name" end  create_table "users", force: true |t| t.string   "name" t.string   "email" t.datetime "created_at" t.datetime "updated_at" t.string   "password_digest" t.string   "remember_token" t.boolean  "admin",              default: false t.string   "image_file_name" t.string   "image_content_type" t.integer  "image_file_size" t.datetime "image_updated_at" t.string   "city_id" t.string   "hood_id" t.string   "burrough_id" end 

i've been looking @ railcast 88 , i've gotten far:

<div class="field">     <%= f.label :city_id %><br>     <%= f.collection_select :city_id, city.order(:id), :id, :name, include_blank: true %> </div> <div id="neighbselect">     <%= f.label :burrough_id %><br>     <%= f.grouped_collection_select :burrough_id, city.order(:name), :burroughs*, :name, :id, :name, include_blank: true %> </div> <div id="neighbselect">     <%= f.label :hood_id %><br>     <%= f_collection_select :hood_id, hood.order(:name), :id, :name, include_blank: true %> </div> 

my question 1) * asterisk there. need define burroughs method, do it, , define as? i'm not sure because

2) i'm having difficulty walking through grouped_collection_select statement. happening here? after grouped_collection_select :burrough_id what? different burroughss based on cities ordered name? have undefined method, , :name, :id.

i'd appreciate little walkthrough on one. i'm stumped! guys

edit i've gotten little farther. added user controller...

def burroughs @burroughs = burrough.all   end 

i still don't seem getting burroughs underneath nyc. check image...

drop-down http://shiftedrecording.com/shiftedaudio/tippedtest/images/screen%20shot%202014-03-24%20at%202.55.26%20pm.png

if come across similar problem, make sure have rake:db migrated sigh


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -