-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the controller and view for Books Search (#101)
Reasons: - The logic to compose the ransack query was added in the controller action and thus is contributing to a fat controller (that already is) => extracted the composition of the query into an object - The form works functionally but would need some small UI tweaks to make it look better => Refactored the Search field to improve UI
- Loading branch information
1 parent
2e79307
commit c41bb23
Showing
3 changed files
with
39 additions
and
22 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
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class Filter | ||
ORDER_BY_FIELD = :created_at | ||
ORDER_BY_DIRECTION = :desc | ||
|
||
def initialize(scope) | ||
@scope = scope | ||
end | ||
|
||
def filter(search_term) = search(search_term).order(order_by) | ||
|
||
private | ||
attr_reader :scope | ||
|
||
def search(search_term) = scope.ransack(title_cont: search_term).result | ||
|
||
def order_by = { ORDER_BY_FIELD => ORDER_BY_DIRECTION } | ||
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