Class: TagsController

Inherits:
BaseController show all
Defined in:
app/controllers/tags_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from BaseHelper

#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #tiny_mce_init_if_needed, #tiny_mce_js, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#auto_complete_for_tag_nameObject



11
12
13
14
15
16
# File 'app/controllers/tags_controller.rb', line 11

def auto_complete_for_tag_name
  @tag_names = ActsAsTaggableOn::Tag.pluck(:name)
  respond_to do |format|
    format.json {render :inline => @tag_names.to_json}
  end
end

#cache_action?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/controllers/tags_controller.rb', line 7

def cache_action?
  !logged_in? && params[:type].blank?
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/tags_controller.rb', line 56

def destroy
  @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id]))
  @tag.destroy

  respond_to do |format|
    format.html {
      flash[:notice] = :tag_was_successfully_deleted.l
      redirect_to admin_tags_url
    }
    format.xml  { render :nothing => true }
  end
end

#editObject



37
38
39
# File 'app/controllers/tags_controller.rb', line 37

def edit
  @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id]))
end

#indexObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/tags_controller.rb', line 18

def index
  @tags = popular_tags(100).to_a

  @user_tags = popular_tags(75, 'User').to_a

  @post_tags = popular_tags(75, 'Post').to_a

  @photo_tags = popular_tags(75, 'Photo').to_a

  @clipping_tags = popular_tags(75, 'Clipping').to_a
end

#manageObject



30
31
32
33
34
# File 'app/controllers/tags_controller.rb', line 30

def manage
  @search = ActsAsTaggableOn::Tag.search(params[:q])
  @tags = @search.result
  @tags = @tags.order('name ASC').distinct.page(params[:page]).per(100)
end

#showObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/tags_controller.rb', line 69

def show
  tag_array = ActsAsTaggableOn::TagList.from( URI::decode(params[:id]) )

  @tags = ActsAsTaggableOn::Tag.where('name IN (?)', tag_array)
  if @tags.nil? || @tags.empty?
    flash[:notice] = :tag_does_not_exists.l_with_args(:tag => tag_array)
    redirect_to :action => :index and return
  end
  @related_tags = @tags.first.related_tags
  @tags_raw = @tags.collect { |t| t.name } .join(',')

  if params[:type]
    case params[:type]
      when 'Post', 'posts'
        @pages = @posts = Post.recent.tagged_with(tag_array).page(params[:page]).per(20)
        @photos, @users, @clippings = [], [], []
      when 'Photo', 'photos'
        @pages = @photos = Photo.recent.tagged_with(tag_array).page(params[:page]).per(30)
        @posts, @users, @clippings = [], [], []
      when 'User', 'users'
        @pages = @users = User.recent.tagged_with(tag_array).page(params[:page]).per(30)
        @posts, @photos, @clippings = [], [], []
      when 'Clipping', 'clippings'
        @pages = @clippings = Clipping.recent.tagged_with(tag_array).page(params[:page]).per(10)
        @posts, @photos, @users = [], [], []
    else
      @clippings, @posts, @photos, @users = [], [], [], []
    end
  else
    @posts      = Post.recent.limit(5).tagged_with(tag_array)
    @photos     = Photo.recent.limit(10).tagged_with(tag_array)
    @users      = User.recent.limit(10).tagged_with(tag_array)
    @clippings  = Clipping.recent.limit(10).tagged_with(tag_array)
  end
end

#updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/tags_controller.rb', line 41

def update
  @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id]))

  respond_to do |format|
    if @tag.update_attributes(params[:tag])
      flash[:notice] = :tag_was_successfully_updated.l
      format.html { redirect_to admin_tags_url }
      format.xml  { render :nothing => true }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @tag.errors.to_xml }
    end
  end
end