Class: Storytime::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/storytime/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #setup, #user_signed_in?

Methods included from Concerns::CurrentSite

#current_storytime_site

Methods included from Concerns::ControllerContentFor

#content_for, #content_for?, #view_context

Instance Method Details

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/storytime/posts_controller.rb', line 5

def show
  params[:id] = params[:id].split("/").last

  @post = if params[:preview]
    Post.find_preview(params[:id])
  else
    Post.published.friendly.find(params[:id])
  end

  authorize @post
  
  content_for :title, "#{@current_storytime_site.title} | #{@post.title}"

  @comments = @post.comments.order("created_at DESC") if @post.show_comments?
  #allow overriding in the host app
  if params[:preview].nil? && !view_context.current_page?(storytime.post_path(@post))
    redirect_to storytime.post_path(@post), :status => :moved_permanently
  elsif lookup_context.template_exists?("storytime/#{@current_storytime_site.custom_view_path}/#{@post.type_name.pluralize}/#{@post.slug}")
    render "storytime/#{@current_storytime_site.custom_view_path}/#{@post.type_name.pluralize}/#{@post.slug}"
  elsif !lookup_show_template_override.nil?
    render lookup_show_template_override
  end
end