Class: RatingsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/ratings_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

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

#destroyObject



27
28
29
30
31
# File 'app/controllers/ratings_controller.rb', line 27

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

#updateObject



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

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