Class: FeedbackEngine::FeedbacksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- FeedbackEngine::FeedbacksController
- Defined in:
- app/controllers/feedback_engine/feedbacks_controller.rb
Constant Summary collapse
- PER_PAGE =
50
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/feedback_engine/feedbacks_controller.rb', line 29 def create feedback = Feedback.new(feedback_params) feedback.user_agent = request.user_agent (feedback) error = attach_screenshots(feedback) return render json: { errors: [error] }, status: :unprocessable_entity if error if feedback.save FeedbackEngine.config.on_submit.call(feedback) head :created else render json: { errors: feedback.errors. }, status: :unprocessable_entity end end |
#destroy ⇒ Object
50 51 52 53 |
# File 'app/controllers/feedback_engine/feedbacks_controller.rb', line 50 def destroy @feedback.destroy! redirect_to root_path, status: :see_other end |
#index ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/feedback_engine/feedbacks_controller.rb', line 14 def index @status = Feedback::STATUSES.include?(params[:status]) ? params[:status] : 'open' @kind = FeedbackEngine.config.kinds.map(&:to_s).include?(params[:kind]) ? params[:kind] : nil @counts = Feedback.group(:status).count scope = Feedback.where(status: @status) scope = scope.where(kind: @kind) if @kind @page = [params[:page].to_i, 1].max @feedbacks = scope.newest_first.offset((@page - 1) * PER_PAGE).limit(PER_PAGE + 1).to_a @more = @feedbacks.size > PER_PAGE @feedbacks = @feedbacks.first(PER_PAGE) end |
#show ⇒ Object
27 |
# File 'app/controllers/feedback_engine/feedbacks_controller.rb', line 27 def show; end |
#update ⇒ Object
45 46 47 48 |
# File 'app/controllers/feedback_engine/feedbacks_controller.rb', line 45 def update @feedback.update!(params.require(:feedback).permit(:status)) redirect_back fallback_location: feedback_path(@feedback), status: :see_other end |