Sha256: cb3a4ba789ad7b0eae8f492f65f26a57a1b17caaf30d87fe06052e20591b74ab

Contents?: true

Size: 1.7 KB

Versions: 40

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Renalware
  module System
    class UserFeedbackController < BaseController
      include Concerns::Pageable

      def new
        feedback = UserFeedback.new
        authorize feedback
        render_new(feedback)
      end

      def create
        feedback = UserFeedback.new(user_feedback_params)
        feedback.author = current_user
        authorize feedback

        if feedback.save
          redirect_to root_url, notice: "Feedback registered, thank you"
        else
          render_new(feedback)
        end
      end

      def index
        search = UserFeedback
          .includes(:author)
          .order(created_at: :desc)
          .search(search_params)

        feedback_msgs = search.result.page(page).per(per_page)
        authorize feedback_msgs
        render locals: { feedback_msgs: feedback_msgs, search: search }
      end

      def edit
        feedback = UserFeedback.find(params[:id])
        authorize feedback
        render locals: { feedback: feedback }
      end

      def update
        feedback = UserFeedback.find(params[:id])
        authorize feedback
        feedback.update!(user_feedback_admin_params)
        redirect_to system_user_feedback_index_path, notice: "Updated"
      end

      private

      def search_params
        hash = params[:q] || {}
        hash[:s] ||= "created_at desc"
        hash
      end

      def render_new(feedback)
        render :new, locals: { feedback: feedback }
      end

      def user_feedback_params
        params.require(:feedback).permit(:comment, :category)
      end

      def user_feedback_admin_params
        params.require(:feedback).permit(:acknowledged, :admin_notes)
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
renalware-core-2.0.42 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.41 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.40 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.39 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.38 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.37 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.36 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.35 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.34 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.33 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.32 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.31 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.30 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.28 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.27 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.26 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.25 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.24 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.23 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.22 app/controllers/renalware/system/user_feedback_controller.rb