Class: TagFollowingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tag_followings_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /tag_followings POST /tag_followings.xml


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/tag_followings_controller.rb', line 13

def create
  name_normalized = ActsAsTaggableOn::Tag.normalize(params['name'])

  if name_normalized.nil? || name_normalized.empty?
    render :nothing => true, :status => 403
  else
    @tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
    @tag_following = current_user.tag_followings.new(:tag_id => @tag.id)

    if @tag_following.save
      render :json => @tag.to_json, :status => 201
    else
      render :nothing => true, :status => 403
    end
  end
end

#destroyObject

DELETE /tag_followings/1 DELETE /tag_followings/1.xml


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/tag_followings_controller.rb', line 32

def destroy
  tag_following = current_user.tag_followings.find_by_tag_id( params['id'] )
  
  if tag_following && tag_following.destroy
    respond_to do |format|
      format.any(:js, :json) { render :nothing => true, :status => 204 }
    end
  else
    respond_to do |format|
      format.any(:js, :json) {render :nothing => true, :status => 403}
    end
  end
end

#indexObject


46
47
48
49
50
# File 'app/controllers/tag_followings_controller.rb', line 46

def index
  respond_to do |format|
    format.json{ render(:json => tags.to_json, :status => 200) }
  end
end