Sha256: 117012a62bbc08080f90352bf572e1409455d212702e82ae156a59f7e58a0537

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

class Backend::Content::RowsController < BackendController
  before_action :find_row, only: [:move_up, :move_down, :destroy]

  def new
    if params[:klass] && params[:id] && params[:locale]
      instance = params[:klass].constantize.find params[:id]
      row = instance.content_rows.create!(locale: params[:locale])

      redirect_to content_path(instance, params[:locale], "content-row-#{row.id}")
    else
      render text: 'Insufficient params. Please provide klass, id and locale.'
    end
  end

  def move_up
    @row.move_higher
    redirect_back_to_content
  end

  def move_down
    @row.move_lower
    redirect_back_to_content
  end

  def destroy
    @row.destroy
    redirect_back_to_content('content-rows')
  end

  private

  def find_row
    @row = ::ContentRow.find params[:id]
  end

  def content_path(instance, locale, anchor)
    path = "edit_translation_backend_#{instance.class.to_s.downcase}_path"
    send(path, instance, locale, anchor: anchor)
  end

  def redirect_back_to_content(anchor = nil)
    anchor = "content-row-#{@row.id}" unless anchor.present?
    redirect_to content_path(@row.rowable, @row.locale, anchor)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
udongo-1.0.3 app/controllers/backend/content/rows_controller.rb
udongo-1.0.2 app/controllers/backend/content/rows_controller.rb
udongo-1.0.1 app/controllers/backend/content/rows_controller.rb
udongo-1.0.0 app/controllers/backend/content/rows_controller.rb
udongo-0.1.0 app/controllers/backend/content/rows_controller.rb