closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

How to get hash_tree with name scope?

Open suchy opened this issue 8 years ago • 0 comments

Hi,

I have page model with tree structure. I also have scope based on status:

class Page < ApplicationRecord

  has_closure_tree

  STATUSES = %w[draft published].freeze

  enum status: STATUSES

  scope :published, -> { where(status: :published) }
end

I need to create navigation menu which will display only published pages. How can I do this?

If I'm trying to use:

Page.published.hash_tree

I'm getting error:

NoMethodError: undefined method `[]=' for nil:NilClass

... and I understand why (after scope it's not a tree structure any more). Is there any way to achieve that?

Thanks!

suchy avatar May 21 '17 22:05 suchy