Sha256: 6f30029f7096d7b9d677908c759bd39877cd75c9197eda96e2b7002d7dfcf0bc

Contents?: true

Size: 920 Bytes

Versions: 12

Compression:

Stored size: 920 Bytes

Contents

class LikesController < ApplicationController
  # Ensure the suitable tie exists
  before_filter :tie!, :only => :create

  # POST /activities/1/like.js
  def create
    @like = activity!.children.new :verb => "like"
		
    respond_to do |format|
      if @like.save
        tie!.activities << @like
        format.js
      else
        format.js
      end
    end
  end

  def destroy
    if (@like = activity!.liked_by(current_user).first)
      @like.destroy
    end

    respond_to do |format|
      format.js
    end
  end

  private

  def activity
    @activity ||= Activity.find(params[:activity_id])
  end

  def activity!
    activity || raise(ActiveRecord::RecordNotFound)
  end

  def tie
    @tie ||= current_user.sent_ties(:receiver => activity!.receiver,
                                    :relation => activity!.relation).first
  end

  def tie!
    tie || raise(ActiveRecord::RecordNotFound)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
social_stream-0.2.2 app/controllers/likes_controller.rb
social_stream-0.2.1 app/controllers/likes_controller.rb
social_stream-0.2.0 app/controllers/likes_controller.rb
social_stream-0.1.7 app/controllers/likes_controller.rb
social_stream-0.1.6 app/controllers/likes_controller.rb
social_stream-0.1.5 app/controllers/likes_controller.rb
social_stream-0.1.4 app/controllers/likes_controller.rb
social_stream-0.1.3 app/controllers/likes_controller.rb
social_stream-0.1.2 app/controllers/likes_controller.rb
social_stream-0.1.1 app/controllers/likes_controller.rb
social_stream-0.1.0 app/controllers/likes_controller.rb
social_stream-0.0.5 app/controllers/likes_controller.rb