{"id":20496510,"url":"https://github.com/hardpixel/action-crud","last_synced_at":"2025-04-13T18:21:37.636Z","repository":{"id":59150239,"uuid":"105149448","full_name":"hardpixel/action-crud","owner":"hardpixel","description":"Speed up development by making your controllers inherit all restful actions.","archived":false,"fork":false,"pushed_at":"2020-03-06T11:37:44.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-24T09:19:50.424Z","etag":null,"topics":["actionpack","actionview","gem","rails","ruby"],"latest_commit_sha":null,"homepage":"","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/hardpixel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-28T13:06:30.000Z","updated_at":"2020-03-06T11:37:42.000Z","dependencies_parsed_at":"2022-09-13T11:00:32.891Z","dependency_job_id":null,"html_url":"https://github.com/hardpixel/action-crud","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Faction-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Faction-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Faction-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Faction-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardpixel","download_url":"https://codeload.github.com/hardpixel/action-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248759091,"owners_count":21157089,"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":["actionpack","actionview","gem","rails","ruby"],"created_at":"2024-11-15T18:07:30.506Z","updated_at":"2025-04-13T18:21:37.594Z","avatar_url":"https://github.com/hardpixel.png","language":"Ruby","readme":"# ActionCrud\n\nActionCrud speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important. It makes your controllers more powerful and cleaner at the same time. In addition to making your controllers follow a pattern, it helps you to write better code by following fat models and skinny controllers convention.\n\n[![Gem Version](https://badge.fury.io/rb/action_crud.svg)](https://badge.fury.io/rb/action_crud)\n[![Build Status](https://travis-ci.org/hardpixel/action-crud.svg?branch=master)](https://travis-ci.org/hardpixel/action-crud)\n[![Code Climate](https://codeclimate.com/github/hardpixel/action-crud/badges/gpa.png)](https://codeclimate.com/github/hardpixel/action-crud)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'action_crud'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install action_crud\n\n## Usage\n\nTo enable CRUD actions in an ActionController controller, include the `ActionCrud` concern in your class:\n\n```ruby\nclass Post \u003c ActionController::Base\n  include ActionCrud\nend\n```\n\nTo set the controller model and class, use the `set_model_name` and `set_model_class` functions:\n\n```ruby\nclass Post \u003c ActionController::Base\n  # Using the set_model_name function\n  set_model_name 'Post'\n\n  # Or by setting the model_name class attribute\n  self.model_name = 'Post'\n\n  # Using the set_model_class function\n  set_model_class 'Post'\n\n  # Or by setting the model_class class attribute\n  self.model_class = 'Post'\nend\n```\n\nTo set a scope for the index action, use the `set_index_scope` function:\n\n```ruby\nclass Post \u003c ActionController::Base\n  # Using the set_index_scope function\n  set_index_scope :published\n\n  # Or by setting the index_scope class attribute\n  self.index_scope = :published\nend\n```\n\nTo set the permitted parameters for the controller, use the `permit_params` function. The function accepts the options `only`, `except`, `also`, `array`, `hash`. Array and hash options are used to indicate array and hash parameters. If you call the function without options it will permit all the model attribute names except `id`:\n\n```ruby\nclass Post \u003c ActionController::Base\n  # Using the permit_params function\n  permit_params only: [:title, :content], array: [:categories, :tags]\n\n  # Or by setting the permitted_params class attribute\n  self.permitted_params = [:title, :content, [categories: []], [tags: []]]\n\n  private\n\n    # Or by overriding the record_params function\n    def record_params\n      params.require(:post).permit(:title, :content, [categories: []], [tags: []])\n    end\nend\n```\n\nPermitted parameters can also be set in your models or records, if you want to apply some logic, by adding a `permitted_attributes` function. The parameters are loaded with priority `controller` then `record` then `model`, like the example below:\n\n```ruby\nclass Post \u003c ActiveRecord::Base\n  # Set permitted_attributes in model\n  def self.permitted_attributes\n    [:title, :content, :comments]\n  end\n\n  # Set permitted_attributes in record\n  def permitted_attributes\n    if new_record?\n      [:title, :content]\n    end\n  end\nend\n```\n\nIf you use a pagination gem like [SmartPagination](https://github.com/hardpixel/smart-pagination), the index records will be automagically paginated. To set the results limit per page (default: 20), use the `set_per_page` function:\n\n```ruby\nclass Post \u003c ActionController::Base\n  # Using the set_per_page function\n  set_per_page 10\n\n  # Or by setting the per_page class attribute\n  self.per_page = 10\nend\n```\n\nAfter setting up the controller, like the examples above, you will have a fully working CRUD controller with instance variables `@post` and `@posts` available.\n\nActionCrud also injects in your views and controllers the following helpers:\n\n| Paths              | URLs             | Data               | Tags (views only) |\n| :----------------- | :--------------- | :----------------- | :---------------- |\n| `records_path`     | `records_url`    | `current_model`    | `record_link_to`  |\n| `record_path`      | `record_url`     | `current_record`   | `record_links_to` |\n| `new_record_path`  | `new_record_url` | `current_records`  | \u0026nbsp;            |\n| `edit_record_path` | `edit_record_url`| `permitted_params` | \u0026nbsp;            |\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/action-crud.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Faction-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardpixel%2Faction-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Faction-crud/lists"}