Class: Virgo::PostsController

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

Instance Method Summary collapse

Methods included from RenderHelper

#render_content, #with_format

Methods included from ApplicationHelper

#action?, #admin?, #admin_access?, #admin_view?, #alerts, #base_errors, #category_timestamp, #column_timestamp, #compact_html, #controller?, #decode_html_entities, #expanded_post_url, #is_admin_view?, #page_url, #post_time_format, #post_timestamp, #production?, #redis_timestamp_key_for, #site, #site_key, #superuser?, #tabbed_param, #word_count

Instance Method Details

#indexObject



16
17
18
# File 'app/controllers/virgo/posts_controller.rb', line 16

def index
  @posts = Post.posts.publicly_viewable.order(publish_at: :desc).page(params[:page])
end

#latestObject



27
28
29
# File 'app/controllers/virgo/posts_controller.rb', line 27

def latest
  @posts = Post.posts.publicly_viewable.order(publish_at: :desc).page(params[:page])
end

#moreObject



20
21
22
23
24
25
# File 'app/controllers/virgo/posts_controller.rb', line 20

def more
  @posts = Post.order(publish_at: :desc).page(params[:page]).per(6).padding(6)
  render json: {
    html: render_content('/virgo/posts/more', layout: false)
  }
end


47
48
49
# File 'app/controllers/virgo/posts_controller.rb', line 47

def popular
  render json: {html: render_content(partial: "/virgo/page_modules/popular_posts")}
end

#rssObject



51
52
53
54
55
# File 'app/controllers/virgo/posts_controller.rb', line 51

def rss
  @limit = Rails.env.production? ? 50 : 5

  render 'rss.xml', layout: false, content_type: Mime::XML
end

#showObject



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

def show
  # call this in the action so it doesn't run before the action cache wrapper
  set_post

  if old_path?
    redirect_to(post_detail_path(@post), status: :moved_permanently) and return
  end

  if @post.page?
    @page = @post
    render "/virgo/pages/show", layout: "virgo/application"
  else
    render layout: '/virgo/posts'
  end
end

#trackObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/virgo/posts_controller.rb', line 57

def track
  # note: we keep a transient/compact hash record of recent tracks in a hash
  # in memcached to prevent abuse of this endpoint (i.e. the same user
  # can't slam this endpoint w/ js ajax requests to artificially pump up a story)
  tracked = JSON::load(Rails.cache.fetch("tracks[#{client_id}]") || '{}')

  unless tracked[params[:id]]
    set_post
    @post.track_view!
    tracked[@post.id.to_s] = 1
    Rails.cache.write("tracks[#{client_id}]", JSON::dump(tracked))
  end

  head :ok
end