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 exclude objects to be positioned? #125

Closed
axhamre opened this issue Jun 7, 2014 · 6 comments
Closed

How to exclude objects to be positioned? #125

axhamre opened this issue Jun 7, 2014 · 6 comments

Comments

@axhamre
Copy link

axhamre commented Jun 7, 2014

I have a Rails app where a Category has many Post.

scope: :category in the Post class is automatically giving position to posts withing the same category.

How could I exclude posts that has the attribute publishedset to false to be part of the positioning?

@swanandp
Copy link
Contributor

swanandp commented Jun 9, 2014

The following should work; can you try and let me know?

acts_as_list scope: 'category = #{category_id} AND published = 0'

@axhamre
Copy link
Author

axhamre commented Jun 9, 2014

I had to change category to category_id to avoid getting the following error message:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: category: SELECT COUNT(*) FROM "questions" WHERE (category = 2 AND published = 1 AND position = 4)

But the methods don't seem to work properly anymore. E.g. remove_from_list sets the position attribute to nil but the list isn't reordered anymore as it usually is.

Is there anything additionally I should think about to achieve the "normal" behaviour of acts_as_list but on a restricted set of items?

@swanandp
Copy link
Contributor

swanandp commented Jun 9, 2014

Work is in progress to support lambdas as scopes, but for now if 0.4.0 is not working for you, you can try 0.3.0

@axhamre
Copy link
Author

axhamre commented Jun 10, 2014

Thank you!

@axhamre axhamre closed this as completed Jun 10, 2014
@axhamre
Copy link
Author

axhamre commented Apr 7, 2020

Six years later, and I ask myself the same thing all over again. But this time around I feel more comfortable looking for the answer in the source code :)

This works great:

acts_as_list scope: [:category_id, published: false]

@brendon
Copy link
Owner

brendon commented Apr 7, 2020

Haha! Great to see that feature worked for you :) It's certainly been much easier for me since learning to dive into gems and figure things out for myself. If you think this can be better documented, feel free to do a PR for documentation improvement :)

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

No branches or pull requests

3 participants