{"id":15430964,"url":"https://github.com/itmammoth/rails_sortable","last_synced_at":"2025-04-04T10:09:37.795Z","repository":{"id":12800440,"uuid":"15474292","full_name":"itmammoth/rails_sortable","owner":"itmammoth","description":"Easy drag \u0026 drop sorting with persisting the arranged order for rails","archived":false,"fork":false,"pushed_at":"2023-03-27T08:34:35.000Z","size":1170,"stargazers_count":143,"open_issues_count":8,"forks_count":36,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T09:09:26.724Z","etag":null,"topics":["drag-and-drop","gem","rails","ruby","sort"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"dclucas/MOO","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itmammoth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-27T13:28:38.000Z","updated_at":"2024-10-25T01:08:14.000Z","dependencies_parsed_at":"2024-06-18T15:32:24.881Z","dependency_job_id":"09e5e311-a117-444f-aa2d-cd77a80ff57d","html_url":"https://github.com/itmammoth/rails_sortable","commit_stats":{"total_commits":130,"total_committers":9,"mean_commits":"14.444444444444445","dds":0.07692307692307687,"last_synced_commit":"f64ad3db3a49bdc5aa57a3943f679421d95daf4e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmammoth%2Frails_sortable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmammoth%2Frails_sortable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmammoth%2Frails_sortable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmammoth%2Frails_sortable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itmammoth","download_url":"https://codeload.github.com/itmammoth/rails_sortable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"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":["drag-and-drop","gem","rails","ruby","sort"],"created_at":"2024-10-01T18:19:44.043Z","updated_at":"2025-04-04T10:09:37.768Z","avatar_url":"https://github.com/itmammoth.png","language":"Ruby","readme":"# RailsSortable\n[![Build Status](https://travis-ci.org/itmammoth/rails_sortable.svg?branch=use_travis_ci)](https://travis-ci.org/itmammoth/rails_sortable)\n\nRailsSortable is a simple Rails gem that allows you to create a listing view with drag \u0026 drop sorting. The arranged order will be persisted in the table without any pain.\n\n![RailsSortable](https://raw.githubusercontent.com/itmammoth/rails_sortable/master/rails_sortable.gif \"RailsSortable\")\n\n# Setup\n\nAdd the following to your `Gemfile` then run bundle to install them.\n```\ngem 'jquery-rails'\ngem 'jquery-ui-rails'\ngem 'rails_sortable'\n```\n\nAnd then add the following to the asset pipeline in the `application.js`:\n```\n//= require jquery\n//= require jquery_ujs\n//= require jquery-ui/widgets/sortable\n//= require rails_sortable\n```\n\n# Usage\n\nRailsSortable requires a specific column on the ActiveRecord Model for its implementation.\n\nFor instance, the following migration indicates the case that you are attempting to make `Item` model sortable.\n\n```ruby\nclass CreateItems \u003c ActiveRecord::Migration[5.1]\n  def change\n    create_table :items do |t|\n      t.string :title\n      t.integer :sort  # for RailsSortable\n\n      t.timestamps\n    end\n  end\nend\n```\nand `Item` model as\n```ruby\nclass Item \u003c ApplicationRecord\n  include RailsSortable::Model\n  set_sortable :sort  # Indicate a sort column\n  # without_updating_timestamps: true, # If you do NOT want timestamps to be updated on sorting\n  # without_validations: true # If you do NOT want validations to be run on sorting\n\nend\n```\nand `ItemsController` as\n```ruby\nclass ItemsController \u003c ApplicationController\n  def index\n    @items = Item.order(:sort).all\n  end\nend\n```\n\nand the listing view (typically - index.html.erb) as\n```erb\n...\n\u003ctable\u003e\n  \u003ctbody class=\"sortable\"\u003e  \u003c!-- sortable target --\u003e\n    \u003c% @items.each_with_sortable_id do |item, sortable_id| %\u003e\n      \u003ctr id=\"\u003c%= sortable_id %\u003e\"\u003e  \u003c!-- Needs id tag on sorting elements --\u003e\n        \u003ctd\u003e\u003c%= item.title %\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c%= item.sort %\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c%= link_to 'Show', item %\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c%= link_to 'Edit', edit_item_path(item) %\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %\u003e\u003c/td\u003e\n      \u003c/tr\u003e\n    \u003c% end %\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- or just invoke model#sortable_id to get the id for sotable --\u003e\n...\n\u003c% @items.each do |item| %\u003e\n  \u003ctr id=\"\u003c%= item.sortable_id %\u003e\"\u003e\n...\n```\n\nfinally, apply sortable with Javascript.\n\n```javascript\n$(function() {\n  $('.sortable').railsSortable();\n});\n```\n\n## More\nPlease have a look at [Use cases@wiki](https://github.com/itmammoth/rails_sortable/wiki#use-cases) for further information.\n\n# Javascript options\njQuery plugin `railsSortable` is just a wrapper of `jquery.ui.sortable`. therefore it accepts all of `sortable` options.\n\nsee the [http://api.jqueryui.com/sortable/](http://api.jqueryui.com/sortable/) to get the details.\n\n# Contribution\n\nFork it, then install required gems like below.\n```bash\n$ bundle install\n```\n\nPlease give me a PR freely.\n\n### Testing\n```bash\n# Test with a dummy application\n$ spec/dummy/bin/rails db:migrate\n$ spec/dummy/bin/rails s\n# Insert test data\n$ RAILS_ENV=test spec/dummy/bin/rails db:migrate\n$ spec/dummy/bin/rails db:seed\n\n# Run specs\n$ bundle exec rspec\n```\n\n# Licence\n\nMIT Licence.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitmammoth%2Frails_sortable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitmammoth%2Frails_sortable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitmammoth%2Frails_sortable/lists"}