Sha256: ce4035e024da21a0a0b8473a89f9bf3af5c0b2e55cb2676871aa849c7b3a23e3

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require_dependency "easy_reports/application_controller"

module EasyReports
  class ReportsController < ApplicationController
    before_action :set_report, only: [:show, :edit, :update, :destroy]

    def index
      @reports = Report.all

      database_mediator = EasyReports::DatabaseMediator.new
      @table_list = database_mediator.tables
    end

    def show
    end

    def new
      @report = Report.new
    end

    def edit
    end

    def create
      @report = Report.new(report_params)

      if @report.save
        redirect_to @report, notice: 'Report was successfully created.'
      else
        render :new
      end
    end

    def update
      if @report.update(report_params)
        redirect_to @report, notice: 'Report was successfully updated.'
      else
        render :edit
      end
    end

    def destroy
      @report.destroy
      redirect_to reports_url, notice: 'Report was successfully destroyed.'
    end

    private
      def set_report
        @report = Report.find(params[:id])
      end

      def report_params
        params.require(:report).permit(:title, :description)
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
easy_reports-0.0.25 app/controllers/easy_reports/reports_controller.rb
easy_reports-0.0.24 app/controllers/easy_reports/reports_controller.rb