Sha256: d3c771d436a783cc467d2573babfbf81c1bb73710c509e4538572cc24c450475

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

module Tramway::Admin
  class SingletonsController < ApplicationController
    def show
      if model_class.active.first.present?
        @singleton = decorator_class.decorate model_class.active.first
      else
        @singleton_form = form_class.new model_class.new
        render :new
        return
      end
    end

    def edit
      @singleton_form = admin_form_class.new model_class.active.first
    end

    def create
      @singleton_form = admin_form_class.new
      if @singleton_form.submit params[:singleton]
        redirect_to params[:redirect] || singleton_path(model: params[:model])
      else
        render :edit
      end
    end

    def update
      @singleton_form = admin_form_class.new model_class.active.first
      if @singleton_form.submit params[:singleton]
        redirect_to params[:redirect] || singleton_path(model: params[:model])
      else
        render :edit
      end
    end
  end

  private

  # FIXME replace to module
  def singleton_path(*args, **options)
    super args, options.merge(model: params[:model])
  end

  def edit_singleton_path(*args, **options)
    super args, options.merge(model: params[:model])
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tramway-admin-1.18.0.1 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.18 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.17.0.1 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.17 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.16.1.1 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.16.1 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.16.0.2 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.16.0.1 app/controllers/tramway/admin/singletons_controller.rb
tramway-admin-1.16 app/controllers/tramway/admin/singletons_controller.rb