-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: dry-up-posts-controller
Are you sure you want to change the base?
Changes from all commits
286fc98
481a2ed
7e21126
b3300d6
f5cf25a
dca5f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,32 @@ def address | |
[street, city, state, postal_code, country].compact.join(", ") | ||
end | ||
|
||
def self.filter_type(type) | ||
if type.present? | ||
# TODO: For rails 5 we can just do post_type: type | ||
# (see: rails/rails#18387) | ||
where(post_type: post_types[type]) | ||
else | ||
all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just like calling There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
end | ||
end | ||
|
||
def self.filter_near(location) | ||
if location.present? | ||
near(location) | ||
else | ||
all | ||
end | ||
end | ||
|
||
def self.filter_query(query) | ||
if query.present? | ||
search(query) | ||
else | ||
all | ||
end | ||
end | ||
|
||
def self.generate_validation | ||
require "securerandom" | ||
# a collision here has low probability, but might as well check | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these all just handle 'nil' gracefully in the queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea! I did it wrong (see next comment) but I fixed it!