Sha256: 48c586cb6c381a37d719ab78f94e1adb2b72ed19cb1e0f50bb67040f79f007ae

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

class Pulitzer::PartialsController < Pulitzer::ApplicationController
  before_filter :set_partial, only: [:show, :edit, :update]

  def new
    @partial = Pulitzer::Partial.new(partial_params)
    @free_form_section = @partial.free_form_section
    render partial: 'new', locals: { partial: @partial }
  end

  def create
    @free_form_section = Pulitzer::FreeFormSection.find partial_params[:free_form_section_id]
    @partial = @free_form_section.partials.create partial_params
    if @partial && @partial.errors.empty?
      Pulitzer::CreatePartialContentElements.new(@partial).call 
      render partial: 'show_wrapper', locals: { partial: @partial }
    else
      render partial: 'new', locals: {partial: @partial}
    end
  end

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

  def edit
    render partial: 'form', locals: { partial: @partial }
  end

  def update
    @partial.update partial_params
    render partial: 'show', locals: { partial: @partial }
  end

  def update_all
    partials = Pulitzer::Partial.find params[:partial]
    partials.each do |ce|
      new_sort_order = params[:partial].index(ce.id.to_s)
      ce.update_attribute(:sort_order, new_sort_order)
    end
    render nothing: true
  end

  protected

  def partial_params
    params[:partial].permit!
  end

  def set_partial
    @partial = Pulitzer::Partial.find(params[:id])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pulitzer-0.4.1 app/controllers/pulitzer/partials_controller.rb
pulitzer-0.4.0 app/controllers/pulitzer/partials_controller.rb