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

Move search logic from controller into model #25

Open
wants to merge 6 commits into
base: dry-up-posts-controller
Choose a base branch
from

Conversation

cllns
Copy link
Contributor

@cllns cllns commented Nov 23, 2015

Eventually we should consider making a Search class, but for now this is OK I think :)

if type == "needed" || type == "available"
send(type.to_sym)
else
all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason I'm not able to find docs for an 'all' method anywhere. I can infer what it's doing, but is this a builtin for rails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just like calling Post.all, but since we're within Post, we can just say all. This lets us chain them.
For example, you can say Post.where(id: [1,2,3,4,5]).all.all.all.all and it just returns the where.
http://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why I didn't realize this haha. Probably would have answered that immediately by opening a terminal :P.

@cllns
Copy link
Contributor Author

cllns commented Dec 4, 2015

👌 @mi-wood ?

@mi-wood
Copy link
Member

mi-wood commented Dec 5, 2015

lgtm 👯

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

Successfully merging this pull request may close these issues.

2 participants