Class: PostsController

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

Constant Summary

Constants inherited from ApplicationController

ApplicationController::APP_DOMAIN

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #canonical_url, #check_domain, #ensure_domain, #get_notice

Instance Method Details

#feedObject


28
29
30
31
32
# File 'app/controllers/posts_controller.rb', line 28

def feed
  @posts = Post.all

  respond_with(@posts)
end

#indexObject


4
5
6
7
8
9
# File 'app/controllers/posts_controller.rb', line 4

def index
  canonical_url('/posts')
  @posts = Post.paginate(page: params[:page], per_page: 10).order(created_at: :desc)

  respond_with(@posts)
end

#showObject


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

def show
  canonical_url("/posts/#{params[:id]}")
  @post = Rails.cache.fetch("public_post_#{params[:id]}", expires_in: 60.minutes) do
    Post.find_by_slug(params[:id])
  end
  if @post.nil?
    @post = Post.find_by_slug(params[:id].split('-').drop(1).join('-'))
    if !@post.nil?
      return redirect_to post_url(@post), status: :moved_permanently
    else
      raise ActionController::RoutingError.new('Not Found')
    end
  end

  respond_with(@post)
end