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.64 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.63 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.62 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.61 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.60 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.58 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.57 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.56 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.55 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.54 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.53 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.52 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.51 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.50 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.48 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.47 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.46 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.45 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.44 app/controllers/renalware/system/user_feedback_controller.rb
renalware-core-2.0.43 app/controllers/renalware/system/user_feedback_controller.rb