My application using ancestry gem.
class Location < ActiveRecord::Base
has_ancestry :cache_depth => true
has_many :posts
end
class User < ActiveRecord::Base
belongs_to :location
end
I created some random Location,
- Alaska
- California
- Los Angeles
- Fresno
- Cincotta (Fresno)
- Hammond (Fresno)
- Melvin (Fresno)
My question if user sign up form if User select California, display child Los Angles and Fresno, after select Fresno then display it's child.
I got javascript tutorial for Dropdown list http://www.plus2net.com/javascript_tutorial/dropdown-list-demo.php
How is possible work with ancestry gem?
I couldn't understand your question, but try to follow this tutorial:
http://railscasts.com/episodes/262-trees-with-ancestry
I watched it once when needed to work with ancestry gem.
Hope it can help you.
Nested
Firstly, if you wanted to keep them all in a single
dropdown
, we created the following helper which achieves it for you:This will allow you to call:
This will give you the ability to call a single dropdown, which has been nested according to your ancestry associations
--
Ajax
If you want to have double dropdown boxes, you'll probably have to implement an
ajax
function to pull the required data each time the initial dropdown changes: