Class: Api::PageTypeAttributesController
- Inherits:
-
ApiController
- Object
- ActionController::Base
- ApiController
- Api::PageTypeAttributesController
- Defined in:
- app/controllers/api/page_type_attributes_controller.rb
Instance Method Summary collapse
Methods inherited from ApiController
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/api/page_type_attributes_controller.rb', line 15 def create if @page_type && @additional_attribute if @page_type.additional_attributes.include? @additional_attribute render json: { success: false, error: 'Attribute already exists.' }, status: 400 else @page_type.additional_attributes.push @additional_attribute render json: { success: true, page_type: BillyCms::PageTypeSerializer.new(@page_type) } end end end |
#destroy ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/api/page_type_attributes_controller.rb', line 26 def destroy additional_attribute_id = params[:id] @additional_attribute = BillyCms::AdditionalAttribute.find(additional_attribute_id) if @page_type && @additional_attribute unless @page_type.additional_attributes.include? @additional_attribute render json: { success: false, error: "Attribute does not exist on pages of type '#{@page_type.name}'." }, status: 400 else @page_type.additional_attributes.delete(additional_attribute_id) render json: { success: true, page_type: BillyCms::PageTypeSerializer.new(@page_type) } end end end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/api/page_type_attributes_controller.rb', line 7 def index render json: @page_type.additional_attributes end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/api/page_type_attributes_controller.rb', line 11 def show render json: @page_type.additional_attributes.find(params.fetch(:id)) end |