Sha256: 12b45d4c4ce95c2b566a761c07367c366d2781ce7cdd07d5ef1c36b3e182d099

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# Encoding: utf-8
class RatingsController < ApplicationController
  respond_to :json

  def create
    @rating = ::ActsAsStarrable::Rating.new(:starrable_type => params[:stype],
                                            :starrable_id => params[:id],
                                            :rating => params[:value],
                                            :rater_type => params[:rtype],
                                            :rater_id => params[:rid])
    if @rating.save
      render :json => @rating, :status => :created
    else
      render :json => @rating.errors, :status => :unprocessable_entity
    end
  end

  def update
    rating = ::ActsAsStarrable::Rating.find(params[:id])
    if rating.update_attributes(:rating => params[:value])
      render :nothing => true, :status => 204
    else
      render :nothing => true, :status => :unprocessable_entity
    end
  end

  def destroy
    rating = ::ActsAsStarrable::Rating.find(params[:id])
    rating.destroy
    render :nothing => true, :status => 204
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_starrable-0.0.2 app/controllers/ratings_controller.rb