Class: PostsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, PostsHelper
Defined in:
app/controllers/posts_controller.rb

Instance Method Summary collapse

Methods included from PostsHelper

#permalink_url, #post_description_short, #post_descritpion_has_image?, #post_teaser_for, #smart_post_path, #smart_post_url, #text_short, #typography

Methods included from ApplicationHelper

#benchmark, #bootstrap_class_for, #counter_tag, #format_date, #glyphicon, #js_redirect_to, #recaptcha_tags, #send_ga_events, #smart_date, #snippet, #time_or_date

Instance Method Details

#blockObject


46
47
48
49
50
51
52
53
# File 'app/controllers/posts_controller.rb', line 46

def block
  post = Post.find params[:id]

  redirect_to smart_post_path(post)

  authorize post, :update?
  post.update_attribute :stream, :trash
end

#counterObject


39
40
41
42
43
44
# File 'app/controllers/posts_controller.rb', line 39

def counter
  views = Post.where(id: params[:id]).pluck(:views).first
  Post.where(id: params[:id]).update_all accessed_at: Time.now, views: views.to_i + 1

  redirect_to '/counter.png', protocol: request.ssl? ? 'https://' : 'http://'
end

#indexObject


5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/posts_controller.rb', line 5

def index
  @posts = Post.published.recent.includes(:blog).limit(20)

  @posts = @posts.older_than(Time.at(params[:before].to_f)) if params[:before].present?

  @posts = @posts.top if params[:top] == '1'

  respond_to do |format|
    format.html
    format.atom
  end
end

#showObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/posts_controller.rb', line 18

def show
  @post = find_post_by_slug_or_id(params[:slug_id], (params[:id] || params[:slug_id]).to_i)

  if @post.blank?
    raise ActiveRecord::RecordNotFound if params[:slug_id].blank?

    @slug_id = params[:slug_id]
    redirect_to goto_path(url: "http://goo.gl/#{@slug_id}")

    expires_in(1.hour, public: true)
  elsif request.path == URI(smart_post_path(@post)).path
    if @post.blocked?
      render template: 'posts/show_blocked'
    else
      render template: 'posts/show'
    end
  else
    redirect_to smart_post_path(@post)
  end
end