{"id":15821234,"url":"https://github.com/flexoid/mongoid_sortable","last_synced_at":"2025-04-01T06:37:39.789Z","repository":{"id":6353573,"uuid":"7590417","full_name":"flexoid/mongoid_sortable","owner":"flexoid","description":null,"archived":false,"fork":false,"pushed_at":"2013-06-25T09:36:11.000Z","size":112,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T07:44:12.561Z","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/flexoid.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}},"created_at":"2013-01-13T16:37:33.000Z","updated_at":"2017-04-25T23:12:44.000Z","dependencies_parsed_at":"2022-08-20T16:10:37.593Z","dependency_job_id":null,"html_url":"https://github.com/flexoid/mongoid_sortable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexoid%2Fmongoid_sortable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexoid%2Fmongoid_sortable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexoid%2Fmongoid_sortable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexoid%2Fmongoid_sortable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flexoid","download_url":"https://codeload.github.com/flexoid/mongoid_sortable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246598151,"owners_count":20802973,"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","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-10-05T07:21:09.465Z","updated_at":"2025-04-01T06:37:39.769Z","avatar_url":"https://github.com/flexoid.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoidSortable\n[![Build Status](https://travis-ci.org/flexoid/mongoid_sortable.png?branch=master)](https://travis-ci.org/flexoid/mongoid_sortable)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'mongoid_sortable'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install mongoid_sortable\n\n## Usage\n\n#### Model code:\n```ruby\nclass Book\n  include Mongoid::Document\n  include MongoidSortable::Sorting\n  \n  sortable_by :title, :created_at\nend\n```\n\n#### Controller code:\n```ruby\n@books = Book.all\n```\n\n#### View code:\n```ruby\n# Generates ?order_by=created_at_asc or ?order_by=created_at_desc\n# depending on current @book criteria order\nsorting_link(@book, :created_at, 'Book Timestamp')\n\n# Customize link\nsorting_link(@book, :created_at, 'Book Timestamp') do |name, path, current_order, is_active|\n  # Whatever you want to generate based on block parameters\nend\n```\n\nBy default, sorting link has html classes *sorting_link asc/desc* \nand *active* if sorting by that field is enabled now.\n\n* * *\n\n#### There is ability to customize queries generation.\n```ruby\nsortable_by :domestic_gross, :foreign_gross do |gross_type|\n  \"movie_details.grosses.#{gross_type}\"\nend\n```\nUsing this with `domestic_gross_desc`, for example, \ngenerates desceting sorting by `movie_details.grosses.domestic_gross_desc` field.\nIt can be used to get rid of long url parameters which reflects your internal document structure.\n\nAlso you can set block that will be used to generate sorting field \nfor all parameters that don't match to explicit `sortable_by`\n```ruby\ndefault_sorting do |param|\n  \"movie_details.#{param}\"\nend\n```\nSo, for example, `sorting(order_by: ticket_cost_asc)` will generate query \nwith ascenting `movie_details.ticket_cost` sorting.\n\nOf course, you can add more complicated logic inside of `sortable_by` and `default_sorting` block, \nall that you need is to return string with field name.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexoid%2Fmongoid_sortable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflexoid%2Fmongoid_sortable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexoid%2Fmongoid_sortable/lists"}