Class: PostsController

Inherits:
Ecrire::ThemeController show all
Defined in:
lib/ecrire/theme/template/controllers/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #signed_in?, #url

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ecrire/theme/template/controllers/posts_controller.rb', line 4

def index
  @posts = posts.published.includes(:titles).order('published_at DESC').page(params[:page]).per(params[:per])
  @tags = Tag.all

  respond_to do |format|
    format.html
    format.rss
    format.json do
      headers['Access-Control-Allow-Origin'] = '*'
    end
  end
end

#showObject



17
18
19
20
21
22
23
24
25
# File 'lib/ecrire/theme/template/controllers/posts_controller.rb', line 17

def show
  redirect_to :root and return if post.nil?
  redirect_to :root and return unless post.published?
  if post.titles.first != @title
    redirect_to theme.post_path(post.year, post.month, post), status: :moved_permanently
  end

  @suggestions = Post.published.limit(5).where.not(id: post.id)
end