generated from ita-social-projects/DevTemplate
-
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.
added sorting service, added selector on view
- Loading branch information
1 parent
f8acd86
commit 7913b62
Showing
7 changed files
with
49 additions
and
4 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,10 @@ | ||
module Account::ProductsHelper | ||
def collection | ||
[ | ||
[I18n.t("sort.id_asc"), "id asc"], | ||
[I18n.t("sort.id_desc"), "id desc"], | ||
[I18n.t("sort.title_asc"), "title asc"], | ||
[I18n.t("sort.title_desc"), "title desc"] | ||
] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Sort | ||
attr_accessor :collection, :params | ||
|
||
def initialize(collection, params) | ||
@collection = collection | ||
@params = params | ||
end | ||
|
||
def sort | ||
collection.order(sorting_params) | ||
end | ||
|
||
private | ||
|
||
def sorting_params | ||
params.nil? ? "id asc" : (params[:sort].presence || "id asc") | ||
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