-
Notifications
You must be signed in to change notification settings - Fork 176
Description
With the update to make scope method utilize kwargs, is the documentation still accurate?
I originally had code similar to the following:
# Define custom scopes for the index view
scopes do
scope :all
scope :published, { default: true }, -> { Post.published }
scope :drafts, -> { Post.unpublished }
end
This broke after the kwargs update. I have to write it as follows for this to work:
# Define custom scopes for the index view
scopes do
scope(:all)
scope(:published, default: true) { Post.published }
scope(:drafts) { Post.unpublished }
end
Yes, I could use mixed formatting, like:
# Define custom scopes for the index view
scopes do
scope :all
scope(:published, default: true) { Post.published }
scope :drafts, -> { Post.unpublished }
end
but this looks totally inconsistent between each call...
Should the docs be updated to utilize scope(:published, default: true) { Post.published } format such that you can both pass parameters and have a block in the same call?
Leaving off the () will not work when passing a block (scope :published, default: true { Post.published } is invalid)
I think this looks the most consistent:
# Define custom scopes for the index view
scopes do
scope(:all)
scope(:published, default: true) { Post.published }
scope(:drafts) { Post.unpublished }
end
Definitely welcome feedback on how to pass kwargs and the block in the same call and make it look consistent.