From dba01bf83eed749a96a55bb751245568cd476152 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Fri, 18 Aug 2017 14:35:30 +0200 Subject: Refactoring api_keys views with table_builder --- app/controllers/api_keys_controller.rb | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb index 35a84da87..bd225818b 100644 --- a/app/controllers/api_keys_controller.rb +++ b/app/controllers/api_keys_controller.rb @@ -1,22 +1,32 @@ -class ApiKeysController < ChouetteController - defaults :resource_class => Api::V1::ApiKey - - belongs_to :referential +class ApiKeysController < BreadcrumbController + defaults resource_class: Api::V1::ApiKey def create - create! { referential_path(@referential) } + @api_key = Api::V1::ApiKey.new(api_key_params.merge(organisation: current_organisation)) + create! { organisation_api_key_path(resource) } + end + + def index + @api_keys = decorate_api_keys(current_organisation.api_keys.paginate(page: params[:page])) end + def update - update! { referential_path(@referential) } + update! { organisation_api_key_path(resource) } end + def destroy - destroy! { referential_path(@referential) } + destroy! { organisation_api_keys_path } end private def api_key_params - params.require(:api_key).permit( :name ) - end - -end + params.require(:api_key).permit(:name, :referential_id) + end + def decorate_api_keys(api_keys) + ModelDecorator.decorate( + api_keys, + with: ApiKeyDecorator, + ) + end +end -- cgit v1.2.3