Class: CompletionKit::Api::V1::MetricGroupsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- CompletionKit::Api::V1::MetricGroupsController
- Defined in:
- app/controllers/completion_kit/api/v1/metric_groups_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/completion_kit/api/v1/metric_groups_controller.rb', line 15 def create metric_group = MetricGroup.new(metric_group_params.except(:metric_ids)) if metric_group.save replace_metric_memberships(metric_group, params[:metric_ids]) if params.key?(:metric_ids) render json: metric_group.reload, status: :created else render json: {errors: metric_group.errors}, status: :unprocessable_entity end end |
#destroy ⇒ Object
34 35 36 37 |
# File 'app/controllers/completion_kit/api/v1/metric_groups_controller.rb', line 34 def destroy @metric_group.destroy! head :no_content end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/completion_kit/api/v1/metric_groups_controller.rb', line 7 def index render json: MetricGroup.order(created_at: :desc) end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/completion_kit/api/v1/metric_groups_controller.rb', line 11 def show render json: @metric_group end |
#update ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/controllers/completion_kit/api/v1/metric_groups_controller.rb', line 25 def update if @metric_group.update(metric_group_params.except(:metric_ids)) replace_metric_memberships(@metric_group, params[:metric_ids]) if params.key?(:metric_ids) render json: @metric_group.reload else render json: {errors: @metric_group.errors}, status: :unprocessable_entity end end |