Skip to content

How to get hash_tree with name scope? #273

Open
@suchy

Description

@suchy

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions