Questions tagged [awesome-nested-set]
17 questions
7
votes
2 answers
Rails 4 after_save previous_changes not working
I have an after_save callback on a model, and I'm calling previous_changes to see if an attribute (is_complete) changed. Even when the attribute changes, previous_changes returns an empty hash.
Here's the callback:
after_save do |record|
puts…

J Plato
- 888
- 1
- 8
- 17
3
votes
1 answer
Complex categories drop down that depends on the leaf nodes present
I have these relationships
User
has_many :products
has_many :stores
Product
belongs_to :user
belongs_to :store
belongs_to :category
Store
belongs_to :user
has_many :products
Category
acts_as_nested_set
has_many :products
In the…

Skyalchemist
- 461
- 1
- 7
- 18
3
votes
1 answer
How to render a tree from an awesome_nested_set and hit the database only once?
As the title states, I would like to render an ul-li-tree based on an awesome_nested_set model and hit the database only once. I'm using Ruby on Rails 4.1.
My query looks like this:
Page.root.self_and_descendants.where('depth < ?', 2)
What would be…

Robin
- 8,162
- 7
- 56
- 101
3
votes
1 answer
AwesomeNestedSet + Rails 4.1.4 `nested_set_options` throws exception
I have a model called Collection that is configured as such:
acts_as_nested_set scope: :account, dependent: :destroy
belongs_to :parent, class_name: 'Collection'
Using the nested_set_options view helper worked fine until I upgraded to Rails 4.1.4…

Chris Peters
- 17,918
- 6
- 49
- 65
3
votes
6 answers
awesome nested set order by
Im using the awesome nested set plugin for ruby on rails. How do I go about sorting by like :name column or something ?
Currently shows the tree like
A
- C
- B
I want it like
A
- B
- C

Andrew Cetinic
- 2,805
- 29
- 44
2
votes
0 answers
Using awesome_nested_set, how to define a has_many relation with all the descendants as well?
I have a simple product and category models along with product_category models that establishes presence in the product category tree.
Product is always placed to the deepest possible categories.
It is intended to call
root_category =…

lmojzis
- 551
- 7
- 17
1
vote
1 answer
How to restrict access to models in Ruby on Rails 4 using Pundit and Rolify
I have only just jumped on the Rails in the last few months and have run into my first real snag in my current project which I have been unable to find an answer for.
My aim is to implement some fine grained control over which user…

Darragh
- 19
- 1
- 6
0
votes
0 answers
What is the best way to find all the leaves or self if leaf in awesome_nested_set?
I am using awesome_nested_set gem in rails
In my controller I want to return
if it is leaf object
[ Model.find(params[:id]) ] # self object in array
and if it is not leaf, then
Model.find(params[:id]).leaves # all the leaves of this…

Zamir Manihar
- 121
- 12
0
votes
0 answers
Rails 5.1: eager load child records in polymorphic association
I have rather complex association where I use awesone_nested_set gem to manage Ratecard::RuleIndex parents and children:
class Inventory::Inventory < ApplicationRecord
has_many :ratecards_rules, class_name: 'Ratecard::RatecardsRule', through:…

matiss
- 747
- 15
- 36
0
votes
1 answer
awesome_nested_set gem lft does't have default
Hey folks I'm experimenting with the ruby awesome_nested_set gem for the first time.
I'm having an issue with my minitests in a rails-api app. I know what the issue is but am unsure how to fix it at this point.
When I run "rails test" I get a bunch…

user2593486
- 55
- 1
- 8
0
votes
1 answer
Sum of counts for nested models
I have two models: Category and Ad. Category has_many :ads + I added counter cache :ads_count. I use gem awesome_nested_set to make nested categories, so Category1 can be parent/child of Category2 which can be parent of Category3 etc. What I need…
user7010020
0
votes
1 answer
Awesome nestset set ancestor class method
Awesome nested set includes an ancestors instance method:
https://github.com/collectiveidea/awesome_nested_set/wiki/Awesome-nested-set-cheat-sheet
@john = Group.where(name: "John").first
@tree = @john.ancestors
I am looking for a class method that…

Dercni
- 1,216
- 3
- 18
- 38
0
votes
1 answer
Carrierwave Uploads stopped working in model with Awesome Nested Set
In my Rails 4.2 app, the file uploads stopped working for the model which has following
acts_as_nested_set counter_cache: :children_count, touch: true
Removing this line, the uploads starts working again.
I'm managinh content via RailsAdmin using…

lightsaber
- 1,481
- 18
- 37
0
votes
1 answer
How to configure default table columns in awesone_nested_set
Awesome_nested_set gem comes with default columns
:parent_id
:lft
:right
How can I configure them that is use different names for them.

Pikachu-go
- 3,058
- 4
- 20
- 27
0
votes
1 answer
Rails: Enumerate data in the view with different context
I use awesome_nested_set gem for the binary tree in my app.
I need to display the binary tree on the page. Each node in the tree have a button, which shows two next childs.
My current code is not DRY, large and difficult to maintain.
I get all…

user1201917
- 1,360
- 1
- 14
- 27