Sha256: a1805980d95c394ae89cf8dc6957e77985553aecd249a9199eb3447c037238fc

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

class Spree::ReviewsController < Spree::StoreController
  helper Spree::BaseHelper
  before_filter :load_product, :only => [:index, :new, :create]
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404

  def index
    @approved_reviews = Spree::Review.approved.where(product: @product)
  end

  def new
    @review = Spree::Review.new(:product => @product)
    authorize! :create, @review
  end

  # save if all ok
  def create
    params[:review][:rating].sub!(/\s*[^0-9]*\z/,'') unless params[:review][:rating].blank?

    @review = Spree::Review.new(review_params)
    @review.product = @product
    @review.user = spree_current_user if spree_user_signed_in?
    @review.ip_address = request.remote_ip
    @review.locale = I18n.locale.to_s if Spree::Reviews::Config[:track_locale]

    authorize! :create, @review
    if @review.save
      flash[:notice] = Spree.t('review_successfully_submitted')
      redirect_to spree.product_path(@product)
    else
      render :new
    end
  end

  private

  def load_product
    @product = Spree::Product.friendly.find(params[:product_id])
  end

  def permitted_review_attributes
    [:rating, :title, :review, :name]
  end

  def review_params
    params.require(:review).permit(permitted_review_attributes)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jiffyshirts_spree_reviews-2.3.1.2 app/controllers/spree/reviews_controller.rb
jiffyshirts_spree_reviews-2.3.1.1 app/controllers/spree/reviews_controller.rb