Sha256: 5ce42adae9781aa8857e3cc8a9fa27fc95908017aff84cda758d8511b044a9fb

Contents?: true

Size: 1.61 KB

Versions: 19

Compression:

Stored size: 1.61 KB

Contents

class Pulitzer::PartialTypesController < Pulitzer::ApplicationController
  before_action :get_partial_type, only: [:show, :edit, :update, :destroy]

  def index
    @ffst = Pulitzer::FreeFormSectionType.find(params[:ffst_id])
    @partial_types = @ffst.partial_types
    render partial: 'index', locals: { ffst: @ffst }
  end

  def new
    @ffst = Pulitzer::FreeFormSectionType.find(params[:ffst_id])
    @partial_type = @ffst.partial_types.build
    render partial: 'new', locals: { ffst: @ffst, partial_type: @partial_type }
  end

  def create
    @free_form_section_type = Pulitzer::FreeFormSectionType.find partial_type_params[:free_form_section_type_id]
    @partial_type = @free_form_section_type.partial_types.create partial_type_params
    if @partial_type && @partial_type.errors.empty?
      Pulitzer::CreateFreeFormSectionPartials.new(@partial_type).call
      render partial: 'show_wrapper', locals: { partial_type: @partial_type }
    else
      render partial: 'new', locals: { partial_type: @partial_type }
    end
  end

  def show
    render partial: 'show', locals: { partial_type: @partial_type }
  end

  def destroy
    @partial_type.destroy
    head :ok and return
  end

  def update_all
    partial_types = Pulitzer::PartialType.find params[:partial_type]
    partial_types.each do |pt|
      new_sort_order = params[:partial_type].index(pt.id.to_s)
      pt.update_attribute(:sort_order, new_sort_order)
    end
    head :ok and return
  end

  protected

  def get_partial_type
    @partial_type = Pulitzer::PartialType.find(params[:id])
  end

  def partial_type_params
    params[:partial_type].permit!
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pulitzer-0.15.31 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.30 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.29 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.28 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.27 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.26 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.25 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.24 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.23 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.22 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.21 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.20 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.19 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.18 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.17 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.16 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.15 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.14 app/controllers/pulitzer/partial_types_controller.rb
pulitzer-0.15.13 app/controllers/pulitzer/partial_types_controller.rb