{"id":17224819,"url":"https://github.com/pseudomuto/routesjs-rails","last_synced_at":"2025-10-05T03:40:13.057Z","repository":{"id":20877957,"uuid":"24165079","full_name":"pseudomuto/routesjs-rails","owner":"pseudomuto","description":"Bringing Rails Routes to JavaScript","archived":false,"fork":false,"pushed_at":"2014-10-16T21:01:14.000Z","size":612,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T03:48:08.514Z","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/pseudomuto.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":null,"support":null}},"created_at":"2014-09-17T22:42:00.000Z","updated_at":"2014-09-25T20:09:43.000Z","dependencies_parsed_at":"2022-07-26T12:47:11.468Z","dependency_job_id":null,"html_url":"https://github.com/pseudomuto/routesjs-rails","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Froutesjs-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Froutesjs-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Froutesjs-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Froutesjs-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pseudomuto","download_url":"https://codeload.github.com/pseudomuto/routesjs-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245503554,"owners_count":20626190,"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-15T04:12:03.709Z","updated_at":"2025-10-05T03:40:12.995Z","avatar_url":"https://github.com/pseudomuto.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# routesjs-rails\n\n[![Build Status](https://travis-ci.org/pseudomuto/routesjs-rails.svg?branch=master)](https://travis-ci.org/pseudomuto/routesjs-rails)\n[![Gem Version](https://badge.fury.io/rb/routesjs-rails.svg)](https://rubygems.org/gems/routesjs-rails)\n[![Code Climate](https://codeclimate.com/github/pseudomuto/routesjs-rails/badges/gpa.svg)](https://codeclimate.com/github/pseudomuto/routesjs-rails)\n\nMake your Rails routes available in JS!\n\n**Supports Ruby 1.9.3+ and Rails 4.0+**\n\n# Installation\n\n* Add `gem routesjs-rails` to your _Gemfile_ and run `bundle install`\n* Run `rails g routes_js:install`\n* Add `//= require routesjs-rails` to your _application.js_ file.\n\n# Usage\n\nRequiring `routesjs-rails` in your JS manifest, will create a global object called `Routes`. This object\nwill have two methods for every _named_ route in config/routes.rb; the path method and the url\nmethod.\n\nThe _path_ version of the method will return the absolute path to the resource, while the _url_\nversion will return the full (including protocol, hostname, port, etc) URL to the resource.\n\n```javascript\n// e.g.\nRoutes.userPath(1);\nRoutes.rootUrl();\n```\n\nSuppose we have the following in _config/routes.rb_:\n\n```ruby\nRails.application.routes.draw do\n  root: \"home#index\"\n  get \"/google\", to: redirect(\"https://www.google.com/\"), as: :google\n\n  namespace :api do\n    root \"api#index\"\n    resources :users, only: [:index, :show]\n  end\nend\n```\n\nWe would end up with the following routes being defined:\n\nMethod | Result\n------ | ------\n`Routes.rootPath()` | `/`\n`Routes.rootUrl()` | `http://www.example.com/`\n`Routes.googlePath()` | `https://www.google.com/`\n`Routes.googleUrl()` | `https://www.google.com/`\n`Routes.apiRootPath()` | `/api`\n`Routes.apiRootUrl()` | `http://www.example.com/api`\n`Routes.apiUsersPath()` | `/api/users`\n`Routes.apiUsersUrl()` | `http://www.example.com/api/users`\n`Routes.apiUserPath()` | `/api/users/:id`\n`Routes.apiUserUrl()` | `http://www.example.com/api/users/:id`\n\n## Route Parameters\n\nParameters can be passed to a route using arguments to the path/url method. There are two ways to do\nthis, using argument values in the order they're supplied, or by passing an object that responds to\neach route parameter name.\n\n```javascript\n// route in rails: /users/:id/roles/:role_id\nRoutes.userRolePath(1, 2); // returns /users/1/roles/2\nRoutes.userRolePath({ id: 1, role_id: 2 }); // also returns /users/1/roles/2\n```\n\n## Route Formats\n\nYou can generate format (json, html, etc) routes by passing an object with a format property. For\nexample:\n\n`Routes.userRolePath({ id: 1, role_id: 2, format: \"json\" }) // returns /users/1/roles/2.json`\n\nYou can also call the `json(), html(), xml() and none()` methods on routes. Doing so will override \nthe default and object supplied formats. For example:\n\n```javascript\n// assuming .html is the default format in config/initializers/routesjs-rails.rb\napiUsersPath(1) // returns /api/users/1.html\napiUsersPath({ id: 1, format: \"xml\" }) // returns /api/users/1.xml\napiUsersPath({ id: 1, format: \"xml\" }).json() // returns /api/users/1.json\napiUsersPath(1).none() // returns /api/users/1\n```\n\n### Setting a Global Default\n\nThe default format can be set by suppliying a `:default_format` option in the initializer.\n\n```\n# config/initializers/routesjs-rails.rb\nRoutesJS::Routes.init(default_format: :json)\n```\n\nFormats specified on the object will override the default format.\n\n# Choosing Which Routes to Include\n\nRoutes can be selectively included/excluded by passing an array of routes to either `:only` or\n`:except` in the initializer.\n\nFor example:\n\n```\n# in config/initializers/routesjs-rails.rb\n\n# include routes using only\nRoutesJS::Routes.init(only: [:root, :new_user])\n\n# or to exclude routes using except\n# RoutesJS::Routes.init(except: :root)\n```\n\n# Using as a CommonJS Module\n\nIf you'd like to use your routes in a CommonJS module, you'll need to generate the module file by\nrunning the following (`-o` parameter is optional):\n\n```\nrails g routes_js:module [-o \u003cfull_path\u003e]\n```\n\nBy default, this will generate a JS module at _app/assets/javascripts/routejs.js_. If you've\nspecified the `-o` option, the file will be placed where you specified. \n\nNow you can use your module by requiring it: `var Routes = require(\"routesjs\")`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudomuto%2Froutesjs-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpseudomuto%2Froutesjs-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudomuto%2Froutesjs-rails/lists"}