35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/plum/pages_controller.rb', line 35
def show
slug = params[:slug]
@content_type = ContentType.for_site(current_site).find_by(handle: slug)
if @content_type
return render_collection(@content_type)
end
if slug.include?("/")
parts = slug.split("/", 2)
content_type = ContentType.for_site(current_site).find do |candidate|
candidate.route_prefix == parts[0]
end
if content_type
@entry = Entry.for_site(current_site).live
.includes(:content_type, terms: :taxonomy)
.find_by!(content_type: content_type, slug: parts[1])
html = Plum::LiquidRenderer.render_template("entries/#{content_type.handle}", build_context(@entry).to_h)
return render html: html.html_safe, layout: false
end
taxonomy = Taxonomy.for_site(current_site).find_by(slug: parts[0])
if taxonomy
term = taxonomy.terms.find_by!(slug: parts[1])
return render_term_page(taxonomy, term)
end
else
taxonomy = Taxonomy.for_site(current_site).find_by(slug: slug)
return render_taxonomy_index(taxonomy) if taxonomy
end
@entry = Entry.for_site(current_site).live
.includes(:content_type, terms: :taxonomy)
.find_by!(slug: slug)
template = "entries/#{@entry.content_type.handle}"
html = Plum::LiquidRenderer.render_template(template, build_context(@entry).to_h)
render html: html.html_safe, layout: false
rescue ActiveRecord::RecordNotFound
render file: Rails.public_path.join("404.html"), status: :not_found, layout: false
end
|