{"id":15288816,"url":"https://github.com/thecodinghouse/rails_rest_vote","last_synced_at":"2026-02-16T13:09:26.100Z","repository":{"id":56890694,"uuid":"55409238","full_name":"thecodinghouse/rails_rest_vote","owner":"thecodinghouse","description":"RESTful voting gem for rails application","archived":false,"fork":false,"pushed_at":"2021-06-08T07:48:43.000Z","size":90,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-13T06:58:31.220Z","etag":null,"topics":["downvote","like","restful-api","ruby-gem","ruby-on-rails","unlike","upvote","voting"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/rails_rest_vote","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/thecodinghouse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-04T12:25:29.000Z","updated_at":"2021-06-08T07:48:46.000Z","dependencies_parsed_at":"2022-08-21T00:50:26.249Z","dependency_job_id":null,"html_url":"https://github.com/thecodinghouse/rails_rest_vote","commit_stats":null,"previous_names":["tixdo/rails_rest_vote"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thecodinghouse/rails_rest_vote","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodinghouse%2Frails_rest_vote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodinghouse%2Frails_rest_vote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodinghouse%2Frails_rest_vote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodinghouse%2Frails_rest_vote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodinghouse","download_url":"https://codeload.github.com/thecodinghouse/rails_rest_vote/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodinghouse%2Frails_rest_vote/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29508742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["downvote","like","restful-api","ruby-gem","ruby-on-rails","unlike","upvote","voting"],"created_at":"2024-09-30T15:53:18.381Z","updated_at":"2026-02-16T13:09:26.082Z","avatar_url":"https://github.com/thecodinghouse.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RailsRestVote\n[![Gem Version](https://badge.fury.io/rb/rails_rest_vote.svg)](https://badge.fury.io/rb/rails_rest_vote)\n\nRails Rest Vote is a Ruby Gem which adds voting feature to any model of your rails application and exposes its RESTful APIs.\n\nIf you are using any frontend client like angular2 in your web app and also for mobile apps, it is really helpful.\n\n## Prerequisites\n\n#### Enabling CORS\n\nIf you’re building a public API you’ll probably want to enable Cross-Origin Resource Sharing (CORS), in order to make cross-origin AJAX requests possible.\n\nThis is made very simple by the rack-cors gem. Just stick it in your Gemfile like so:\n```\ngem 'rack-cors'\n```\nAnd put something like the code below in config/application.rb of your Rails application. For example, this will allow GET, POST or OPTIONS requests from any origin on any resource.\n```\nmodule YourApp\n  class Application \u003c Rails::Application\n\n    # ...\n\n    config.middleware.insert_before 0, \"Rack::Cors\" do\n      allow do\n        origins '*'\n        resource '*', :headers =\u003e :any, :methods =\u003e [:get, :post, :options]\n      end\n    end\n\n  end\nend\n```\n\u003eFor more detailed configuration options please see the gem [documentation](https://github.com/cyu/rack-cors)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rails_rest_vote'\n```\nAnd then execute:\n\n    $ bundle install\n\nRun the following command in your project folder:\n\n    $ rails g rails_rest_vote MODEL\n\nIn the above command you will need to replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`)\n\nIt will do 3 things for you:\n\n- Create a migration file of Vote table in db/migrate/ folder.\n- Insert association in user model i.e has_many :votes\n- Create vote model i.e app/models/vote.rb\n\nAfter that migrate database by using.\n\n    $ rake db:migrate\n\nNow you are good to go.\n\n## Usage\n\nAdd below line to the model for which you want to record `upvote/downvote` or `like/unlike` functionality:\n\n    has_many :votes, :as =\u003e :votable\n\nIt can be used in 2 ways, I am using `Post` model in below examples:\n\n1. Use as `upvote/downvote` ( _stackoverflow_):\n\n    ##### APIs\n\n    \u003e /api/votes/up\n\n    API is used for upvote on model.\n    ```\n    method: POST\n    body: {\"votable_id\":\"1\",\"votable_type\":\"Post\",\"user_id\":\"1\"}\n    content-type: application/json\n    response: {\"status\":200,\"message\":\"upvoted successfully.\"}\n    ```\n\n    \u003e /api/votes/down\n\n    API is used for downvote on model.\n    ```\n    method: POST\n    body: {\"votable_id\":\"1\",\"votable_type\":\"Post\",\"user_id\":\"1\"}\n    content-type: application/json\n    response: {\"status\":200,\"message\":\"downvoted successfully.\"}\n    ```\n     \u003e /api/votes/user?user_id=1\n\n    API returns upvote and downvote count done by a particular user.\n    ```\n    method: GET\n    content-type: application/json\n    response: {\"status\":200,\"upcount\":1,\"upvotes\":[{\"id\":1,...}], \"downcount\":1,\"downvotes\":[{\"id\":3,...}]}\n    ```\n      \u003e /api/votes/model?votable_id=1\u0026votable_type=Post\n\n    API returns upvote and downvote count done on a particular model.\n    ```\n    method: GET\n    content-type: application/json\n    response: {\"status\":200,\"upcount\":1,\"upvotes\":[{\"id\":1,...}], \"downcount\":1,\"downvotes\":[{\"id\":3,...}]}\n    ```\n\n2. Use as `like/unlike` ( _facebook_):\n\n    ##### APIs\n\n    \u003e /api/likes\n\n    Same API is used for like and unlike functionality.For the first time if you hit this API , it will work as `like` and if you send same parameters second time it will remove record from the vote table i.e `unlike`\n    ```\n    method: POST\n    body: {\"votable_id\":\"1\",\"votable_type\":\"Post\",\"user_id\":\"1\"}\n    content-type: application/json\n    response: {\"status\":200,\"message\":\"liked successfully.\"}\n    ```\n    \u003e /api/likes/user?user_id=1\n\n    API returns like count done by a particular user.\n    ```\n    method: GET\n    content-type: application/json\n    response: {\"status\":200,\"likecount\":1,\"likes\":[{\"id\":1,...}]}\n    ```\n    \u003e /api/likes/model?votable_id=1\u0026votable_type=Post\n\n    API returns like count done on a particular model.\n    ```\n    method: GET\n    content-type: application/json\n    response: {\"status\":200,\"likecount\":1,\"likes\":[{\"id\":1,...}]}\n    ```\n    \n\u003e`user_id` inside request body can be `admin_id`, it depends on the application’s users model (it’s frequently `User` but could also be `Admin`)\n\n\u003eNote: Depending on your use case, both features can be used in same application.\n\n## Token-based authentication\n\nIf you are using **Token-based authentication** for authorizing requests, You can do in ApplicationController of your app.\n```\n# app/controllers/application_controller.rb \nclass ApplicationController \u003c ActionController::API \n    before_action :authenticate_request \n    attr_reader :current_user \n    \n    private \n    def authenticate_request\n       # Here you can read headers and check for current user. this example is for `jwt` check below link for more.\n       @current_user = AuthorizeApiRequest.call(request.headers).result render json: { error: 'Not Authorized' }, status: 401 unless @current_user \n    end \nend\n```\n\u003eRead [token-based-authentication-with-ruby-on-rails-5-api](https://www.pluralsight.com/guides/ruby-ruby-on-rails/token-based-authentication-with-ruby-on-rails-5-api) blog post for integration.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/thecodinghouse/rails_rest_vote. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodinghouse%2Frails_rest_vote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodinghouse%2Frails_rest_vote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodinghouse%2Frails_rest_vote/lists"}