Sha256: cd6466c1e59fded961f91cbd9864c8f826dffffdae7981db0679772267f2f054

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

class Backend::SnippetsController < BackendController
  include Concerns::Backend::TranslatableController

  before_action :find_model, only: [:edit, :update]
  before_action -> { breadcrumb.add t('b.snippets'), backend_snippets_path }

  def index
    @snippets = ::Snippet.order(:description)
  end

  def new
    @model = ::Snippet.new
  end

  def create
    @model = ::Snippet.new allowed_params

    if @model.save
      redirect_to edit_translation_backend_snippet_path(@model, translation_locale: default_locale), notice: translate_notice(:added, :snippet)
    else
      render :new
    end
  end

  def update
    if @model.update_attributes(allowed_params)
      redirect_to edit_backend_snippet_path(@model), notice: translate_notice(:edited, :snippet)
    else
      render :edit
    end
  end

  private

  def find_model
    @model = ::Snippet.find params[:id]
  end

  def translation_form
    Backend::SnippetTranslationForm.new(
      snippet: @model,
      translation: @model.translation(params[:translation_locale])
    )
  end

  def allowed_params
    params.require('snippet').permit(:identifier, :description)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
udongo-1.0.0 app/controllers/backend/snippets_controller.rb
udongo-0.1.0 app/controllers/backend/snippets_controller.rb