Ruby on rails 祖先:从范围中跳过元素

Ruby on rails 祖先:从范围中跳过元素,ruby-on-rails,activerecord,ancestry,Ruby On Rails,Activerecord,Ancestry,使用宝石血统 如何从Category::ActiveRecordRelation中跳过self元素或需要使用范围 = simple_form_for @category do |f| = f.input :parent_id, collection: Category.roots 比如: = f.input :parent_id, collection: Category.roots.except(@category) 我正在使用它,但我认为这是从宝石祖先那里实现的。 = f.inpu

使用宝石血统

如何从Category::ActiveRecordRelation中跳过self元素或需要使用范围

= simple_form_for @category do |f|
  = f.input :parent_id, collection: Category.roots 
比如:

= f.input :parent_id, collection: Category.roots.except(@category)

我正在使用它,但我认为这是从宝石祖先那里实现的。
= f.input :parent_id, collection: Category.roots.where("id <> ?", @category.id)
scope :except, lambda{ |category| where("id <> ?", category.id) }
= f.input :parent_id, collection: Category.roots.except(@category)