Sha256: b9e85ec617c892deb5a312ac254240feb2e61feda6db333a893c34a14bb90ef7

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

Contents

module Ecrire
  class PostsController < ::ApplicationController
    # TODO: This should be included. I have no idea why this isn't.
    # It actually is loaded in dev as soon as the reloader reloads the files
    include Rails.application.routes.url_helpers

    before_action :pagination, only: :index
    protect_from_forgery except: :index

    helper_method :post

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

    def show
      redirect_to :root and return if post.nil?
      redirect_to :root and return unless post.published?
    end

    protected

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

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

    def pagination
      params[:per] ||= 10
      params[:page] ||= 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecrire-0.22.1 lib/ecrire/app/controllers/ecrire/posts_controller.rb
ecrire-0.21.0 lib/ecrire/app/controllers/ecrire/posts_controller.rb