Class: Plum::Cp::ContentTypesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Plum::Cp::ContentTypesController
- Defined in:
- app/controllers/plum/cp/content_types_controller.rb
Instance Method Summary collapse
- #apply_fieldset ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#apply_fieldset ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 45 def apply_fieldset fieldset = current_site.fieldsets.find(params[:fieldset_id]) existing_handles = @content_type.fields.map { |field| field["handle"].to_s } inserted_handles = Array(fieldset.fields).map { |field| field["handle"].to_s } collisions = existing_handles & inserted_handles if collisions.any? return render json: { error: "Field handles already exist: #{collisions.join(', ')}" }, status: :unprocessable_entity end blueprint = @content_type.blueprint.to_h.deep_dup blueprint["fields"] = @content_type.fields.deep_dup + Array(fieldset.fields).deep_dup if @content_type.update(blueprint: blueprint) render json: { applied: true, redirect_url: edit_cp_content_type_path(@content_type) } else render json: { error: @content_type.errors..to_sentence }, status: :unprocessable_entity end end |
#create ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 20 def create @content_type = current_site.content_types.build(content_type_params) if @content_type.save redirect_to cp_content_type_path(@content_type), notice: "Content type created" else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
40 41 42 43 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 40 def destroy @content_type.destroy redirect_to cp_content_types_path, notice: "Content type deleted" end |
#edit ⇒ Object
29 30 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 29 def edit end |
#index ⇒ Object
8 9 10 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 8 def index @content_types = ContentType.for_site(current_site) end |
#new ⇒ Object
16 17 18 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 16 def new @content_type = current_site.content_types.build end |
#show ⇒ Object
12 13 14 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 12 def show @entries = @content_type.entries.order(updated_at: :desc) end |
#update ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/controllers/plum/cp/content_types_controller.rb', line 32 def update if @content_type.update(content_type_params) redirect_to cp_content_type_path(@content_type), notice: "Content type updated" else render :edit, status: :unprocessable_entity end end |