{"id":20513641,"url":"https://github.com/theopencms/simple_sort","last_synced_at":"2025-08-02T12:10:36.168Z","repository":{"id":71919645,"uuid":"84730984","full_name":"TheOpenCMS/simple_sort","owner":"TheOpenCMS","description":"Gem helps provide simple sorting on AR collections","archived":false,"fork":false,"pushed_at":"2017-10-01T15:27:51.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T15:12:10.511Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheOpenCMS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-12T14:16:21.000Z","updated_at":"2017-03-12T14:19:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7d9b250-5526-406b-a884-57181c02c51f","html_url":"https://github.com/TheOpenCMS/simple_sort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TheOpenCMS/simple_sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fsimple_sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fsimple_sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fsimple_sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fsimple_sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheOpenCMS","download_url":"https://codeload.github.com/TheOpenCMS/simple_sort/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheOpenCMS%2Fsimple_sort/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268385921,"owners_count":24242105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T21:12:21.394Z","updated_at":"2025-08-02T12:10:36.146Z","avatar_url":"https://github.com/TheOpenCMS.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"```ruby\nThis gem is a part of TheOpenCMS project. https://github.com/TheOpenCMS\n```\n\n# SimpleSort\n\nGem provides simple sort on Active Record collections.\n\n# How it works\n\nAdd `SimpleSort` functionality to your Model\n\n```ruby\nclass Product  \u003c ApplicationRecord\n  include ::SimpleSort::Base\nend\n```\n\nUse method `simple_sort` with your Model in a controller like this:\n\n```ruby\nclass ProductsController \u003c ApplicationController\n  def index\n    @products = Product.simple_sort(params)\n  end\nend\n```\n\n* Use `simple_sort_url` helper in your views to provide sorting for required field\n* Use `reset_simple_sort` helper to reset current sort params\n\n```ruby\n= link_to 'Reset sort params', url_for(reset_simple_sort)\n\n= link_to 'Title ↕',      simple_sort_url(:title)\n= link_to 'Created At ↕', simple_sort_url(:crated_at)\n= link_to 'Updated At ↕', simple_sort_url(:updated_at)\n```\n\n# Bonus methods for Models\n\nAlso gem provides some dead-simple but helpful methods\n\n* `max2min` for descending order `DESC` (1000, 102, 15, 3)\n* `min2max` for ascending order `ASC` (3, 15, 102, 1000)\n* `random` random record from a database (`mysql`, `psql`)\n\n```ruby\nclass ProductsController \u003c ApplicationController\n  def index\n    @products = Product.max2min(:created_at)\n    @articles = Article.min2max(:title)\n    @banners  = Banner.random.limit(3)\n  end\nend\n```\n\n### How to test\n\n```\ngit clone https://github.com/TheOpenCMS/simple_sort.git\n\ncd simple_sort/tests/dummy_app/\nbundle\n\nRAILS_ENV=test bundle exec rake db:setup\n\nbundle exec rspec\n```\n\n### Contributors\n\n* Author: [@the-teacher](https://github.com/the-teacher)\n* [@devico](https://github.com/devico)\n\n### MIT License\n\n* [MIT License](./LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopencms%2Fsimple_sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopencms%2Fsimple_sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopencms%2Fsimple_sort/lists"}