使用宝石祖先。
如何从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)
或通过范围
类别.rb
scope :except, lambda{ |category| where("id <> ?", category.id) }
然后
= f.input :parent_id, collection: Category.roots.except(@category)