Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get hash_tree with name scope? #273

Open
suchy opened this issue May 21, 2017 · 0 comments
Open

How to get hash_tree with name scope? #273

suchy opened this issue May 21, 2017 · 0 comments
Labels

Comments

@suchy
Copy link

suchy commented May 21, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants