{"id":13878341,"url":"https://github.com/rubymonolith/restomatic","last_synced_at":"2026-01-11T04:53:35.322Z","repository":{"id":57698247,"uuid":"500704825","full_name":"rubymonolith/restomatic","owner":"rubymonolith","description":"Rapidly build controllers in Rails that map cleanly to resources and models","archived":false,"fork":false,"pushed_at":"2023-03-31T23:54:31.000Z","size":90,"stargazers_count":49,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-19T12:58:25.234Z","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/rubymonolith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-06-07T05:42:31.000Z","updated_at":"2024-11-07T11:53:06.000Z","dependencies_parsed_at":"2022-08-25T11:11:47.374Z","dependency_job_id":null,"html_url":"https://github.com/rubymonolith/restomatic","commit_stats":null,"previous_names":["rocketshipio/oxidizer"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubymonolith%2Frestomatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubymonolith%2Frestomatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubymonolith%2Frestomatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubymonolith%2Frestomatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubymonolith","download_url":"https://codeload.github.com/rubymonolith/restomatic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"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-08-06T08:01:46.793Z","updated_at":"2026-01-11T04:53:35.316Z","avatar_url":"https://github.com/rubymonolith.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# RESTomatic\n\n[![Test](https://github.com/rubymonolith/restomatic/actions/workflows/test.yml/badge.svg)](https://github.com/rubymonolith/restomatic/actions/workflows/test.yml)\n[![Gem Version](https://badge.fury.io/rb/restomatic.svg)](https://badge.fury.io/rb/restomatic)\n\nRESTomatic helps Rails developers organize nested resources with automatic namespacing. Each nested resource gets its own controller module, making your app cleaner and easier to maintain.\n\nUnlike Rails shallow routes that send everything to one controller, RESTomatic enforces proper separation: `Blogs::PostsController`, `Users::PostsController`, etc. keeping your controllers organized and your codebase more maintainable.\n\n## Installation\n\nAdd to your Rails application Gemfile:\n\n```ruby\nbundle add \"restomatic\"\n```\nThat's it! The routing helpers are automatically available in your `config/routes.rb` file.\n\nThen start using more RESTful routes in `config/routes.rb`:\n\n```ruby\nresources :blogs do\n  nest :posts do                    # Blogs::PostsController\n    collection do\n      get :search                   # Blogs::PostsController#search\n    end\n  end\nend\n\nresources :posts do\n  create :comments                  # Posts::CommentsController#new, #create\nend\n```\n\n## The Problem\n\nRails provides shallow routes and nested resources, but the syntax becomes verbose and repetitive, especially when you want to properly namespace controllers.\n\n### Before RESTomatic\n\n```ruby\nresources :blogs do\n  scope module: :blogs do\n    resources :posts, only: %i[index new create] do\n      collection do\n        get :search\n      end\n    end\n  end\nend\n\nresources :posts do\n  scope module: :posts do\n    resources :comments, only: %i[new create]\n  end\nend\n```\n\n### With RESTomatic\n\n```ruby\nresources :blogs do\n  nest :posts do                    # Blogs::PostsController\n    collection do\n      get :search                   # Blogs::PostsController#search\n    end\n  end\nend\n\nresources :posts do\n  create :comments                  # Posts::CommentsController#new, #create\nend\n```\n\nMuch cleaner! The `nest` helper automatically:\n- Scopes to the parent resource's module (e.g., `Blogs::PostsController`)\n- Sets sensible defaults for which actions are included\n- Reduces boilerplate while maintaining Rails conventions\n\n## Route Helpers\n\n### `nest`\n\nNest resources under a parent with automatic module scoping and sensible action defaults.\n\n```ruby\nresources :blogs do\n  nest :posts         # Creates index, new, create actions under Blogs::PostsController\n  nest :post          # Singular: creates new, create actions (no edit/update/destroy)\nend\n```\n\n**Options:**\n- `except:` - Exclude specific actions (overrides defaults)\n- Singular resources default to excluding: `[:edit, :update, :destroy]`\n- Plural resources default to excluding: `[:show, :edit, :update, :destroy]`\n\n**Module-only nesting:**\n\n```ruby\nresources :posts do\n  nest do\n    # Routes defined here will be scoped to Posts module\n    # without creating a nested resource\n    get :analytics\n  end\nend\n```\n\n### `create`\n\nDefine routes for creating a resource (new + create actions only).\n\n```ruby\nresources :posts do\n  create :comments    # Only new and create actions\nend\n\ncreate :session       # Works with both singular and plural forms\n```\n\n### `edit`\n\nDefine routes for editing a resource (edit + update actions only).\n\n```ruby\nresources :posts do\n  edit :metadata      # Only edit and update actions\nend\n```\n\n### `show`\n\nDefine routes for showing a resource (show action only).\n\n```ruby\nresources :posts do\n  show :preview       # Only show action\nend\n```\n\n### `destroy`\n\nDefine routes for destroying a resource (destroy action only).\n\n```ruby\nresources :posts do\n  destroy :attachment # Only destroy action\nend\n```\n\n### `list`\n\nDefine routes for listing resources (index action only).\n\n```ruby\nresources :users do\n  list :posts         # Only index action\nend\n```\n\n## Real-World Example\n\n```ruby\nRails.application.routes.draw do\n  root \"home#index\"\n\n  # Public blog routes\n  resources :blogs, only: [:index, :show] do\n    list :posts                              # Blogs::PostsController#index\n  end\n\n  # Admin area with nested resources\n  namespace :admin do\n    resources :blogs do\n      nest :posts do                         # Admin::Blogs::PostsController\n        create :comments                     # Admin::Blogs::Posts::CommentsController#new, #create\n        collection do\n          get :scheduled                     # Admin::Blogs::PostsController#scheduled\n          post :bulk_publish                 # Admin::Blogs::PostsController#bulk_publish\n        end\n      end\n    end\n\n    resources :posts do\n      edit :seo                              # Admin::Posts::SeosController#edit, #update\n      show :preview                          # Admin::Posts::PreviewsController#show\n      destroy :featured_image                # Admin::Posts::FeaturedImagesController#destroy\n    end\n  end\n\n  # User account management\n  resource :account do\n    nest do\n      edit :profile                          # Accounts::ProfilesController#edit, #update\n      edit :password                         # Accounts::PasswordsController#edit, #update\n      show :billing                          # Accounts::BillingsController#show\n    end\n  end\nend\n```\n\n## How It Works\n\nRESTomatic extends `ActionDispatch::Routing::Mapper` to add these helper methods. The helpers automatically:\n\n1. Detect singular vs. plural resource names\n2. Apply appropriate module scoping\n3. Set sensible action defaults based on the helper used\n4. Work seamlessly with existing Rails routing features\n\n## Philosophy\n\nRails routing is powerful but can become verbose when building properly organized applications with shallow routes and namespaced controllers. RESTomatic embraces Rails conventions while reducing boilerplate, making your routes file more readable and maintainable.\n\n## Requirements\n\n- Rails 7.0+\n- Ruby 3.0+\n\n## Contributing\n\n1. Fork the repository\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 a new Pull Request\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubymonolith%2Frestomatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubymonolith%2Frestomatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubymonolith%2Frestomatic/lists"}