Sha256: 59da4863948ec5ce2912fdfc5f4f87795a8f87d062a7140ea2ec2d26f1322b07

Contents?: true

Size: 716 Bytes

Versions: 3

Compression:

Stored size: 716 Bytes

Contents

class PostsController < Ecrire::ThemeController
  helper_method :post, :posts

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

  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
  end

  protected

  def posts
    @posts ||= Post.published.page(params[:page]).per(params[:per]).order('published_at DESC')
  end

  def post
    @title ||= Title.find_by_slug(params[:id])
    @post ||= @title.post
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ecrire-0.25.2 lib/ecrire/theme/template/controllers/posts_controller.rb
ecrire-0.25.1 lib/ecrire/theme/template/controllers/posts_controller.rb
ecrire-0.25.0 lib/ecrire/theme/template/controllers/posts_controller.rb