Sha256: b90c3a83ece5d7918c9d56d08a9054c9406be25da2a151062464cebd9315575f

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module Workarea
  class Admin::ReviewsController < Admin::ApplicationController
    required_permissions :marketing
    before_action :find_review, except: :index

    def index
      search = Search::AdminReviews.new(params.merge(autocomplete: request.xhr?))
      @search = Admin::ReviewsSearchViewModel.new(search, view_model_options)
    end

    def show
      redirect_to edit_review_path(@review)
    end

    def edit; end

    def update
      if @review.update_attributes(review_params)
        flash[:success] = t('workarea.admin.reviews.flash_messages.updated')
        redirect_to reviews_path
      else
        render :edit
      end
    end

    def destroy
      @review.destroy
      flash[:success] = t('workarea.admin.reviews.flash_messages.destroyed')
      if params[:product].present?
        redirect_to reviews_catalog_product_path(params[:product])
      else
        redirect_to reviews_path
      end
    end

    private

    def find_review
      if params[:id].present?
        review = Review.find(params[:id])
        @review = Admin::ReviewViewModel.wrap(review)
        @user = User.find(review.user_id) rescue nil
      end
    end

    def review_params
      return {} if params[:review].blank?
      params[:review].permit(:body, :approved, :rating, :title)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-reviews-3.1.2 app/controllers/workarea/admin/reviews_controller.rb
workarea-reviews-3.1.1 app/controllers/workarea/admin/reviews_controller.rb
workarea-reviews-3.1.0 app/controllers/workarea/admin/reviews_controller.rb
workarea-reviews-3.0.10 app/controllers/workarea/admin/reviews_controller.rb
workarea-reviews-3.0.9 app/controllers/workarea/admin/reviews_controller.rb
workarea-reviews-3.0.8 app/controllers/workarea/admin/reviews_controller.rb