README.md in power_resource-0.0.1 vs README.md in power_resource-0.0.2

- old
+ new

@@ -1,15 +1,14 @@ # PowerResource -Power up your RESTful resources! +Power up RESTful resources! -ALPHA STAGE, DO NOT USE IN PRODUCTION! - ## Requirements -* Ruby 2.0.0 or greater -* Rails 4.0.0 or greater +* Ruby 2.0 or greater +* Rails 4.0 or greater +* Active Record 4.0 or greater ## Installation Add this line to your application's Gemfile: @@ -23,24 +22,92 @@ $ gem install power_resource ## Usage +### Basic Usage + Inherit your resource controllers from PowerResource::BaseController: - class ProductsController < PowerResource::BaseController + class PostsController < PowerResource::BaseController end -## Helpers +### Strong Parameters -Besides all [helpers from Inherited Resources gem](https://github.com/josevalim/inherited_resources#url-helpers), next helper methods are available: +Permit **only** title and content (recommended way): + class PostsController < PowerResource::BaseController + def permit_attributes + %w(title content) + end + end + +Permit **all** attributes: + + class PostsController < PowerResource::BaseController + def permit_attributes + resource_attributes + end + end + +Permit all attributes **except** id: + + class PostsController < PowerResource::BaseController + def permit_attributes + resource_attributes - %w(id) + end + end + +Permit all **human-readable attributes** (all except id, created\_at and +updated\_at): + + class PostsController < PowerResource::BaseController + def permit_attributes + resource_human_attributes + end + end + +Permit all **human-readable attributes, except** title and content: + + class PostsController < PowerResource::BaseController + def permit_attributes + resource_human_attributes - %w(title content) + end + end + +Setting default behaviour can be done in ApplicationController: + + class ApplicationController < ActionController::Base + def permit_attributes + resource_human_attributes + end + end + +Also, you can use [Inherited Resources +way](https://github.com/josevalim/inherited_resources#strong-parameters) way: + + class PostsController < PowerResource::BaseController + def permitted_params + params.permit(post: %w(title content)) + end + end + +### Helpers + +Besides all [helpers from Inherited Resources +gem](https://github.com/josevalim/inherited_resources#url-helpers), next helper +methods are available: + resource_form_path #=> /products when creating a new resource #=> /products/1 when resource already exists ## Support -If you have any questions or issues with PowerResource, or if you like to report a bug, please create an [issue on GitHub](https://github.com/jarijokinen/power_resource/issues). +If you have any questions or issues with PowerResource, or if you like to +report a bug, please create an [issue on +GitHub](https://github.com/jarijokinen/power_resource/issues). ## License -MIT License. Copyright (c) 2013 [Jari Jokinen](http://jarijokinen.com). See [LICENSE](https://github.com/jarijokinen/power_resource/blob/master/LICENSE.txt) for further details. +MIT License. Copyright (c) 2013 [Jari Jokinen](http://jarijokinen.com). See +[LICENSE](https://github.com/jarijokinen/power_resource/blob/master/LICENSE.txt) +for further details.