{"id":15537335,"url":"https://github.com/nullvoxpopuli/lazy_crud","last_synced_at":"2025-04-23T14:06:48.075Z","repository":{"id":31803002,"uuid":"35369575","full_name":"NullVoxPopuli/lazy_crud","owner":"NullVoxPopuli","description":"Lazy way to implement common actions in controllers in Rails","archived":false,"fork":false,"pushed_at":"2016-01-26T12:34:12.000Z","size":98,"stargazers_count":12,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T22:03:13.598Z","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/NullVoxPopuli.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":"2015-05-10T12:14:44.000Z","updated_at":"2023-11-30T17:52:47.000Z","dependencies_parsed_at":"2022-08-20T23:40:11.293Z","dependency_job_id":null,"html_url":"https://github.com/NullVoxPopuli/lazy_crud","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/NullVoxPopuli%2Flazy_crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Flazy_crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Flazy_crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Flazy_crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NullVoxPopuli","download_url":"https://codeload.github.com/NullVoxPopuli/lazy_crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250447998,"owners_count":21432164,"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-02T11:56:12.696Z","updated_at":"2025-04-23T14:06:48.038Z","avatar_url":"https://github.com/NullVoxPopuli.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazy_crud [![Join the chat at https://gitter.im/NullVoxPopuli/lazy_crud](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/NullVoxPopuli/lazy_crud?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nLazy way to implement common actions in controllers in Rails\n\n[![docs](https://img.shields.io/badge/docs-yardoc-blue.svg?style=flat-square)](http://www.rubydoc.info/github/NullVoxPopuli/lazy_crud)\n[![Gem Version](http://img.shields.io/gem/v/lazy_crud.svg?style=flat-square)](http://badge.fury.io/rb/lazy_crud)\n[![Build Status](http://img.shields.io/travis/NullVoxPopuli/lazy_crud.svg?style=flat-square)](https://travis-ci.org/NullVoxPopuli/lazy_crud)\n[![Code Climate](http://img.shields.io/codeclimate/github/NullVoxPopuli/lazy_crud.svg?style=flat-square)](https://codeclimate.com/github/NullVoxPopuli/lazy_crud)\n[![Test Coverage](http://img.shields.io/codeclimate/coverage/github/NullVoxPopuli/lazy_crud.svg?style=flat-square)](https://codeclimate.com/github/NullVoxPopuli/lazy_crud)\n[![Dependency Status](http://img.shields.io/gemnasium/NullVoxPopuli/lazy_crud.svg?style=flat-square)](https://gemnasium.com/NullVoxPopuli/lazy_crud)\n\n\n## Features\n\n - Minimal Controller Coding\n - Resource Can be Scoped to Parent Resource\n - Uses the [responders](https://github.com/plataformatec/responders) gem\n   - Enables i18n on flash messages\n   - Defaultily enables html and json response types\n     - Good for rails apps with an api and / or transitioning to a js framework\n   - Responders is a great gem with lots of flexibility. Be sure to check it out.\n\n## Installation\n\nGemfile\n\n```ruby\ngem 'lazy_crud'\n```\n\nTerminal\n\n```ruby\ngem install lazy_crud\n```\n\n## Configuration\n\n\n### Basic setup\n\nTo include all of the basic actions, `create`, `edit`, `destroy`, etc,\njust add `include LazyCrud` to any controller.\n\n```ruby\nclass SomeObjectsController \u003c ApplicationController\n  include LazyCrud\n```\n\nJust make sure the model `SomeObject` exists.\n\n**Optional**\n\nThis is for in the case of you having nested routes, and want to scope\n`SomeObject` to its parent object.\n\nFor example: `/event/:event_id/discounts/:id`\nEvent is the parent object and Discount is the resource\n\nNote that there must be an `@event` instance variable set.\nSee specs for details.\n\n```ruby\nset_resource_parent Event\n```\n\nHowever, if you follow standard naming conventions, you can omit the above line\nand have a controller that looks like this:\n\n```ruby\nParent::ExamplesController \u003c ApplicationController\n    include LazyCrud\n```\n\nand the `Parent` class would be set as the resource parent.\n\nJust make sure that a `Parent` `has_many :examples`\n\nNote that if you use a namespace that isn't named after a model, the resource_parent will not be set.\nIt will output to the debug log though, saying that the namespace doesn't match up with a model.\n\n**Sort of Optional**\n\nIf you want to be able to update / create objects, you'll want to\nspecify what parameters are allowed to be set.\nThis uses strong parameters.\n\n```ruby\nset_param_whitelist(:name, :amount)\n```\n\n### CRUD-hooks\n\nSometimes you may want to manually assign attributes to an object before saving, such as current_user.\n\nThere are two ways to do this:\n\n```ruby\ndef before_create\n  @resource.user = current_user\nend\n```\n\nor if you are wanting to have ruby throw an error if you spelled something wrong\n\n```ruby\nbefore_create -\u003e(resource){ resource.user = current_user }\n```\n\nthe error thrown will be NoMethodError\n\nAvailable CRUD-hooks are: `before_create`, `before_update`, `before_destroy`\n\nEach hook can be called multiple times, and they will be invoked in the order they were defined. If the `def` method is used, it will be invoked last.\n\n### Overridng\n\nIf you really don't want any default functionality, you can always override\n\n```ruby\ndef index\n  @raffles = @event.raffles.with_deleted\nend\n```\n\n## Contributing\n\n1. Fork the project\n2. Create a new, descriptively named branch\n3. Add Test(s)!\n4. Commit your proposed changes\n5. Submit a pull request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullvoxpopuli%2Flazy_crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnullvoxpopuli%2Flazy_crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullvoxpopuli%2Flazy_crud/lists"}