forked from rubyforgood/homeward-tails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
795 Add additional filters on staff pet view (rubyforgood#1046)
* Add published/paused/placement_type filters to staff pet view * Move ransack methods on Pet model to concern
- Loading branch information
Showing
4 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module PetRansackable | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def ransackable_attributes(auth_object = nil) | ||
%w[name sex species breed placement_type application_paused published] | ||
end | ||
|
||
def ransackable_associations(auth_object = nil) | ||
["adopter_applications"] | ||
end | ||
|
||
def ransackable_scopes(auth_object = nil) | ||
[:ransack_adopted, :ransack_birth_date] | ||
end | ||
|
||
# Using string values to get around ransack bug: https://github.com/activerecord-hackery/ransack/issues/1375 | ||
def ransack_adopted(adoption_state) | ||
(adoption_state == "adopted") ? adopted : unadopted | ||
end | ||
|
||
def ransack_birth_date(date) | ||
start_date, end_date = date.split("/") | ||
|
||
if start_date != "none" && end_date != "none" | ||
where("birth_date >= ? AND birth_date <= ?", start_date, end_date) | ||
elsif start_date == "none" && end_date != "none" | ||
where("birth_date <= ?", end_date) | ||
elsif start_date != "none" && end_date == "none" | ||
where("birth_date >= ?", start_date) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters