class PostsController

Public Instance Methods

index() click to toggle source
# 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
show() click to toggle source
# 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

Protected Instance Methods

post() click to toggle source
# File lib/ecrire/theme/template/controllers/posts_controller.rb, line 33
def post
  @title ||= Title.find_by_slug(params[:id])
  @post ||= @title.post
end
posts() click to toggle source
# File lib/ecrire/theme/template/controllers/posts_controller.rb, line 29
def posts
  @posts ||= Post.published.page(params[:page]).per(params[:per]).order('published_at DESC')
end