Sha256: becf37efbe959d5de9e05246a2ddc2f5f16153c80f3c904d42d9f545df5d1592

Contents?: true

Size: 812 Bytes

Versions: 11

Compression:

Stored size: 812 Bytes

Contents

class LikesController < ApplicationController
  def create
    positive = request.original_url.match('/like/') ? true : false
    like_or_dislike = current_user.likes_or_dislikes.where(target_type: params[:target_type], target_id: params[:target_id]).first
    
    if like_or_dislike
      like_or_dislike.update_attribute(:positive, positive)
    else
      current_user.likes_or_dislikes.create!(positive: positive, target_type: params[:target_type], target_id: params[:target_id])
    end
    
    render nothing: true
  end
  
  def destroy
    like_or_dislike = current_user.likes_or_dislikes.where(target_type: params[:target_type], target_id: params[:target_id]).first
    
    raise ActiveRecord::RecordNotFound unless like_or_dislike
    
    like_or_dislike.destroy!
    render nothing: true
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
voluntary-0.7.1 app/controllers/likes_controller.rb
voluntary-0.7.0 app/controllers/likes_controller.rb
voluntary-0.6.0 app/controllers/likes_controller.rb
voluntary-0.5.2 app/controllers/likes_controller.rb
voluntary-0.5.1 app/controllers/likes_controller.rb
voluntary-0.5.0 app/controllers/likes_controller.rb
voluntary-0.4.0 app/controllers/likes_controller.rb
voluntary-0.3.0 app/controllers/likes_controller.rb
voluntary-0.2.4 app/controllers/likes_controller.rb
voluntary-0.2.3 app/controllers/likes_controller.rb
voluntary-0.2.2 app/controllers/likes_controller.rb