Ancestry: skip element from scope
-
30-06-2021 - |
Question
Using gem ancestry.
How skip self element from Category::ActiveRecordRelation or need use scope?
= simple_form_for @category do |f|
= f.input :parent_id, collection: Category.roots
Something like:
= f.input :parent_id, collection: Category.roots.except(@category)
La solution
= f.input :parent_id, collection: Category.roots.where("id <> ?", @category.id)
or via a scope
category.rb
scope :except, lambda{ |category| where("id <> ?", category.id) }
then
= f.input :parent_id, collection: Category.roots.except(@category)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow