Class: TagsController

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

Constant Summary

Constants included from PaginationHelper

PaginationHelper::DEFAULT_OPTIONS, PaginationHelper::OPTIONS

Instance Method Summary collapse

Methods included from PaginationHelper

included, #paginate, validate_options!

Instance Method Details

#addObject



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

def add
  post      = Post.find(@params['post_id'])
   = post.tags.collect { |t| t.tag }
  unless @params['tags'].empty?
    @params['tags'].split(',').each do |tag|
      unless .include? tag.strip
        thetag = Tag.find_by_tag(tag.strip) || Tag.new('tag' => tag.strip)
        thetag.increment('numitems')
        thetag.save
        post.tags << thetag
      end
    end
  end
  redirect_to :controller => 'post', :action => 'view', :id => post.id
end

#addxmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/tags_controller.rb', line 28

def addxml
  @post = Post.find(@params['post_id'])
   = @post.tags.collect { |t| t.tag }
  unless @params['tags'].empty?
    @params['tags'].split(',').each do |tag|
      unless .include? tag.strip
        thetag = Tag.find_by_tag(tag.strip) || Tag.new('tag' => tag.strip)
        thetag.increment('numitems')
        thetag.save
        @post.tags << thetag
      end
    end
  end
  render_without_layout 'tags/addxml'
end

#indexObject



2
3
4
# File 'app/controllers/tags_controller.rb', line 2

def index
  @tags = Tag.find_all(nil, 'tag')
end

#searchObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/tags_controller.rb', line 44

def search
  if @params['qu']
    if /,\W*$/ =~ @params['qu']
      render_without_layout 'tags/no_completions'
      return
    end
    
    items = @params['qu'].split(',')
    item = items[-1].strip
    
    if items.length > 1
      notin = "AND tag NOT IN ("
      notin += items[0...-1].collect {|t| "'#{t.strip}'"}.join(',') + ")"
    else
      notin = ''
    end
    if item != ''
      @tags = Tag.find_all("tag LIKE '#{item}%' #{notin}", 'tag')
    else
      @tags = []
    end
    
    @tagarray   = @tags.collect { |t| "\"#{t.tag}\"" }.join(', ')
    @postsarray = @tags.collect { |t| "\"#{t.posts_count} posts\"" }.join(', ')
    
    render_without_layout 'tags/search_completer'
  else
    render_without_layout 'tags/search'
  end
end

#showObject



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

def show
  @tag   = Tag.find_by_tag(CGI.unescape(@params['tag'])) rescue Tag.new
  @posts = @tag.posts
  render 'post/index'
end