Class: Shoppy::ReviewsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shoppy/reviews_controller.rb

Direct Known Subclasses

ReviewsController

Instance Method Summary collapse

Instance Method Details

#deleteObject



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/shoppy/reviews_controller.rb', line 58

def delete
  review = Review.find_by(id: params[:review_id])
  if review
    review.destroy
    Log.newEvent("Review", "Review '#{review.id}' for product '#{review.product.name}' was deleted", current_admin.name)
    flash[:notice] = "review has been deleted."
    redirect_to '/reviews'
  else
    page_not_found
  end
end

#editObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/shoppy/reviews_controller.rb', line 27

def edit
  review = Review.find_by(id: params[:review_id])
  (product = Product.find_by(id: params[:product_id])) if params[:product_id]
  if review
    if params[:status] == "approve"
      review.accepted = true
      review.save
      flash[:notice] = "Review has been approved."
      Log.newEvent("Review", "Review '#{review.id}' for product '#{review.product.name}' was approved", current_admin.name)
    elsif params[:status] == "disapprove"
      review.accepted = false
      review.save
      flash[:notice] = "Review has been disapproved."
      Log.newEvent("Review", "Review '#{review.id}' for product '#{review.product.name}' was disapproved", current_admin.name)
    else
      flash[:warning] = "Something went wrong. please try again"
    end
    if params[:view] = "show"
      redirect_to "/reviews/#{review.id}"
    else
      if product
        redirect_to "/products/items/#{product.id}/reviews"
      else
        redirect_to "/reviews"
      end
    end
  else
    page_not_found
  end
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/shoppy/reviews_controller.rb', line 5

def index
  if params[:product_id]
    @product = Product.find_by(id: params[:product_id])
    if @product
      @reviews = Review.where(product_id: params[:product_id])
    else
      page_not_found
    end
  else
    @reviews = Review.all
  end
end

#showObject



18
19
20
21
22
23
24
25
# File 'app/controllers/shoppy/reviews_controller.rb', line 18

def show
  r = Review.find_by(id: params[:review_id])
  if r
    @review = r
  else
    page_not_found
  end
end