Sha256: 2d1387c023338c447bc452ba1c4c571b0252791b32cbfd24a6cc236d26ac0411
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true class PostsController < ApplicationController before_action :find_structure, only: [:index, :show, :search] before_action :perpage!, only: [:index, :search] caches_page :index, :show def index @posts = Post.filter(params).per(params[:per]) if params[:q].blank? && params[:tag].present? && @posts.empty? raise ActiveRecord::RecordNotFound, 'Posts not found' end respond_with @posts end def search params[:per] = 10 if params[:per].blank? || params[:per].to_i < 1 @posts = Post.filter(params).per(params[:per]) render :index end def show @post = Post.past.find_by(slug: params[:id]) raise ActiveRecord::RecordNotFound, "Post #{params[:id]} not found" unless @post # Seo meta tags @meta_record = @post respond_with @post end protected def render_meta_tag_content_title(meta_tag) meta_tag.content = "#{category_prefix}#{meta_tag.content}" super end def render_meta_tag_content_description(meta_tag) meta_tag.content = "#{category_prefix}#{meta_tag.content}" super end def category_prefix return '' if @category.blank? || @category.title.blank? "#{@category.title}: " end private def find_structure load_structure(StructureType.posts) @recently = Post.past.limit(5) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
translation_cms-0.1.5 | app/controllers/posts_controller.rb |