Ancestry is a gem/plugin that allows the records of a Ruby on Rails ActiveRecord model to be organised as a tree structure
Questions tagged [ancestry]
194 questions
9
votes
3 answers
How to generate json tree from ancestry
I use ancestry to make a tree of goals. I would like to send the contents of that tree to the browser using json.
My controller is like this:
@goals = Goal.arrange
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml =>…

Johan Hovda
- 855
- 2
- 10
- 23
8
votes
1 answer
Heroku only: ancestry gem crashes with undefined method `ancestry' for #
I'm seeing an issue on Heroku only with the ancestry gem (cannot reproduce locally):
https://github.com/stefankroes/ancestry
A NoMethodError occurred in home#upload:
undefined method `ancestry' for #
Method looks like this:
def anthem_upload
…

etayluz
- 15,920
- 23
- 106
- 151
5
votes
2 answers
Pluck and ids give array of non unique elements
In console:
Course.ids.count
=> 1766
Course.pluck(:id).count
=> 1766
Course.ids.uniq.count
=> 1529
Course.count
=> 1529
It's normal?
small comment - model Course uses ancestry (gem).
UPD1:
Generated sql:
Learn::Course.ids.count
(5.4ms) SELECT…

Gena Shumilkin
- 713
- 4
- 16
5
votes
1 answer
How to eager load roots using ancestry gem with rails?
I have an Entry model that belongs to a Category. The Category model is using ancestry so that I can nest Categories.
I want to group a selection of entries by their root category. The problem I have is that in order to do this, rails executes a…

Christian
- 19,605
- 3
- 54
- 70
5
votes
1 answer
Building family trees using HTML/JS/CSS/PHP/MySQL
I've been tasked to build something similar to this and I need some suggestions/opinions for an effective solution:
http://familyecho.com
So far, I've tried to represent my data using the Nested Set Model but I don't think its possible to have…

georaldc
- 1,880
- 16
- 24
4
votes
1 answer
How to perform eager loading on model descendants using Rails and Ancestry
As for now I'm working on a blog application that has article/comment models connected via has_many/belongs_to associations. To create nested comments functionality I use ancestry gem. However, I would like to eager load all of the descendants of a…

kushnir
- 53
- 5
4
votes
3 answers
Does The Ancestry Gem Work With Rails 4?
Only mentions Rails 3 in the GitHub documentation - does anyone know if it's compatible with Rails 4?
I ask because it looks like it's been updated to handle Ruby 2.1.0

Richard Peck
- 76,116
- 9
- 93
- 147
4
votes
2 answers
Rails ancestry with nil parent
I'm building a hierarchical category in Rails using Ancestry, and I allow the user to choose the parent of the object they're creating. I display the existing categories using a dropdown:
<%= f.input :ancestry, collection: Category.sorted_list…

kid_drew
- 3,857
- 6
- 28
- 38
4
votes
2 answers
Can I create an activerecord association through an activerecord relation (when using the ancestry gem)?
I am using the ancestry gem in my rails project to create a hierarchy of groups. A group can belong to a parent group and can have many children groups. Each group can have many users who belong to a group. The model looks like this:
class Group <…

George Bailey
- 41
- 1
3
votes
1 answer
Rails - Self joins with ancestry, possible to have nested routes and slugs?
The goal is to create the following URL routes:
localhost:3000/category-1/location-1/
localhost:3000/category-1/location-1/sub-location-2
localhost:3000/category-1/location-1/sub-location-2/sub-location-3
I have a series of locations that have…

Kobius
- 674
- 7
- 28
3
votes
1 answer
Full Rails 5 routes with Ancestry Gem nested tree
I am using the Ancestry Gem in my Rails 5 app and all things look and act as they should and my database looks good. I just can't figure out out how to show the full url path after the first level following the model name.
For Example
I need…

Charles Smith
- 3,201
- 4
- 36
- 80
3
votes
1 answer
FactoryGirl - how to create hierarchy of records?
trying to create factory for nested Region records. I'm using ancestry gem for this purpose. Region is associated entity for Place
Place factory:
factory :place, traits: [:pageable] do
...
association :region, factory:…

divideByZero
- 1,120
- 16
- 27
3
votes
0 answers
ancestry gem with position sorting
I use ancestry gem for create nested categories. this gem is super fast but how can i add position filed to ancestry.
I want tree item sort by parent and child & position. think you create category like:
games
- football
- tennis
after a while…

Armanlearn
- 51
- 1
- 5
3
votes
0 answers
Direct parent change callback using ancestry gem in ruby
I am trying to check if the direct parent of any record changed to do some stuff. I have searched a lot but I didn't find node.parent_changed?. I only found node.ancestry_changed?. But the problem with that is, it returns any node that has any…

Haytham.Breaka
- 155
- 12
3
votes
3 answers
How to implement ancestry for this specific situation
We have a Real-Estate app in which the User can be a Renter or Landlord(Owner). Renters can search for specific houses listed by the Owners. Renters can also add other persons(friends or acquaintances who are staying with that specific renter). In…

Pavan
- 33,316
- 7
- 50
- 76