Sha256: c4f0f0736cd005907a247c5a5feaf31f8e0e68b09c6f5bc2c244849ff75c78ee

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationController
  def index
    scope = params[:scope].present? ? params[:scope] : :all
    records = model_class.active.order(id: :desc).send scope
    records = records.full_text_search params[:search] if params[:search]
    records = records.ransack(params[:filter]).result if params[:filter].present?
    records = records.send "#{current_user.role}_scope", current_user.id
    @records = decorator_class.decorate records.page params[:page]
  end

  def show
    @record = decorator_class.decorate model_class.active.find params[:id]
  end

  def new
    @record_form = admin_form_class.new model_class.new
  end

  def create
    @record_form = admin_form_class.new model_class.new
    if @record_form.submit params[:record]
      redirect_to params[:redirect] || record_path(@record_form.model)
    else
      render :new
    end
  end

  def edit
    @record_form = admin_form_class.new model_class.active.find params[:id]
  end

  def update
    @record_form = admin_form_class.new model_class.active.find params[:id]
    if @record_form.submit params[:record]
      redirect_to params[:redirect] || record_path(@record_form.model)
    else
      render :edit
    end
  end

  def destroy
    record = model_class.active.find params[:id]
    record.remove
    redirect_to records_path
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tramway-admin-1.20.3 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.2.4 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.2.3 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.2.2 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.2.1 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.2 app/controllers/tramway/admin/records_controller.rb
tramway-admin-1.20.1 app/controllers/tramway/admin/records_controller.rb