README.md in administrate-base_controller-0.2.0 vs README.md in administrate-base_controller-0.3.0

- old
+ new

@@ -39,10 +39,14 @@ | `edit_page` | `new_page` | Allows you to overwrite the `edit` page | | `edit_page` | `new_page` | Allows you to overwrite the `edit` page | | `authorize_resource` | `show_action?(action_name.to_sym, resource)` | Allows you to change how resources are authorized | | `resource_params` | Calls `read_param(k, v)` for each instead of `transform_values` | Allows you to change how params are read | | `read_param` | Calls `read_param_value` if applicable | Allows you to change how a param is read based on its key | +| `render_index_json` | `json: resources.to_json` | Easily override json responses on the index route without changing the resources logic | +| `render_index_any` | `locals: resources, page, ...` | Easily override any responses on the index route without changing the resources logic | +| `render_show_json` | `json: resource.to_json` | Easily override json responses on the show route without changing the resources logic | +| `render_show_any` | `locals: resource, page, ...` | Easily override any responses on the show route without changing the resources logic | ```ruby module Admin class ApplicationController < Administrate::ApplicationController # everything is available now @@ -58,11 +62,11 @@ module Admin class ApplicationController < Administrate::ApplicationController def current_ability @_current_ability ||= Ability.new(current_admin_user) end - + def show_action?(action, resource) current_ability.can?(action.to_sym, resource) end end end @@ -71,17 +75,17 @@ Additionally you can correctly hide resources the `current_ability` can not `action`: ```ruby module Admin class ApplicationController < Administrate::ApplicationController - + # ... - + def scoped_resource super.accessible_by(current_ability, action_name.to_sym) end - end + end end ``` ### Integrate with FriendlyId @@ -89,12 +93,12 @@ ```ruby module Admin class BookController < ::Admin::ApplicationController def find_resource(param) - scoped_resource.friendly.find(param) - end + scoped_resource.friendly.find(param) + end end end ``` ### Only show subset of resources on index @@ -105,11 +109,11 @@ ```ruby module Admin class BookController < ::Admin::ApplicationController def index_scoped_resource super.where(author: Current.author) - end + end end end ``` This only shows the books with the `Current.author`, but if you access `/book/uuid`, it will find the book even if its @@ -122,11 +126,11 @@ ```ruby module Admin class BookController < ::Admin::ApplicationController def new_resource resource_class.new(author: Current.author) - end + end end end ``` ### Deserialize attributes (e.g. JSON field) @@ -136,38 +140,38 @@ ```ruby module Admin class BookController < ::Admin::ApplicationController JSON_FIELDS = %w[options content].freeze - + def read_param(key, value) return Oj.load(value) if JSON_FIELDS.include?(String(key)) super(key, value) end - end + end end ``` Alternatively you can use the [`administrate-serialized_fields`](https://github.com/XPBytes/administrate-serialized_fields) gem. ## Related - [`Administrate`](https://github.com/thoughtbot/administrate): A Rails engine that helps you put together a super-flexible admin dashboard. -<!-- - [`Administrate::BaseController`](https://github.com/XPBytes/administrate-base_controller): A set of application controller improvements. --> ### Concerns -- [`Administrate::DefaultOrder`](https://github.com/XPBytes/administrate-default_order): Sets the default order for a resource in a administrate controller. -- [`Administrate::SerializedFields`](https://github.com/XPBytes/administrate-serialized_fields): Automatically deserialize administrate fields on form submit. +- [`Administrate::DefaultOrder`](https://github.com/XPBytes/administrate-default_order): :1234: Sets the default order for a resource in a administrate controller. +- [`Administrate::SerializedFields`](https://github.com/XPBytes/administrate-serialized_fields): :ab: Automatically deserialize administrate fields on form submit. ### Fields -- [`Administrate::Field::Code`](https://github.com/XPBytes/administrate-field-code): A `text` field that shows code. -- [`Administrate::Field::Hyperlink`](https://github.com/XPBytes/administrate-field-hyperlink): A `string` field that is shows a hyperlink. -- [`Adminisrtate::Field::JsonEditor`](https://github.com/XPBytes/administrate-field-json_editor): A `text` field that shows a [JSON editor](https://github.com/josdejong/jsoneditor). -- [`Administrate::Field::ScopedBelongsTo`](https://github.com/XPBytes/administrate-field-scoped_belongs_to): A `belongs_to` field that yields itself to the scope `lambda`. -- [`Administrate::Field::ScopedHasMany`](https://github.com/XPBytes/administrate-field-scoped_has_many): A `has_many` field that yields itself to the scope `lambda`. -- [`Administrate::Field::TimeAgo`](https://github.com/XPBytes/administrate-field-time_ago): A `date_time` field that shows its data as `time_ago` since. +- [`Administrate::Field::Code`](https://github.com/XPBytes/administrate-field-code): :pencil: A `text` field that shows code. +- [`Administrate::Field::Hyperlink`](https://github.com/XPBytes/administrate-field-hyperlink): :pencil: A `string` field that is shows a hyperlink. +- [`Adminisrtate::Field::JsonEditor`](https://github.com/XPBytes/administrate-field-json_editor): :pencil: A `text` field that shows a [JSON editor](https://github.com/josdejong/jsoneditor). +- [`Administrate::Field::LazyBelongsTo`](https://github.com/XPBytes/administrate-field-lazy_belongs_to): :pencil: An input field that lazy loads `belongs_to` values. +- [`Administrate::Field::ScopedBelongsTo`](https://github.com/XPBytes/administrate-field-scoped_belongs_to): :pencil: A `belongs_to` field that yields itself to the scope `lambda`. +- [`Administrate::Field::ScopedHasMany`](https://github.com/XPBytes/administrate-field-scoped_has_many): :pencil: A `has_many` field that yields itself to the scope `lambda`. +- [`Administrate::Field::TimeAgo`](https://github.com/XPBytes/administrate-field-time_ago): :pencil: A `date_time` field that shows its data as `time_ago` since. ## Development After 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.