From d6761a7265a0cf84ddb35ae3bc4dd1227e262791 Mon Sep 17 00:00:00 2001 From: Stephen Nelson Date: Mon, 26 Aug 2024 13:59:21 +0930 Subject: [PATCH] Add preview route to dummy app frontend --- spec/dummy/app/controllers/pages_controller.rb | 8 ++++++-- spec/dummy/app/views/pages/show.html.erb | 2 +- spec/dummy/config/routes.rb | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/dummy/app/controllers/pages_controller.rb b/spec/dummy/app/controllers/pages_controller.rb index 704f561..3d15192 100644 --- a/spec/dummy/app/controllers/pages_controller.rb +++ b/spec/dummy/app/controllers/pages_controller.rb @@ -4,12 +4,16 @@ class PagesController < ApplicationController helper Katalyst::Content::FrontendHelper def show - render locals: { page: } + render locals: { page:, version: page.published_version } + end + + def preview + render :show, locals: { page:, version: page.draft_version } end private def page - @page ||= Page.find_by!(slug: params[:slug]) + @page ||= Page.find_by!(slug: params[:slug] || params[:page_slug]) end end diff --git a/spec/dummy/app/views/pages/show.html.erb b/spec/dummy/app/views/pages/show.html.erb index a01cf29..5a13b25 100644 --- a/spec/dummy/app/views/pages/show.html.erb +++ b/spec/dummy/app/views/pages/show.html.erb @@ -2,4 +2,4 @@

<%= page.title %>

-<%= render_content page.published_version %> +<%= render_content version %> diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 526a249..d876276 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -7,7 +7,9 @@ resources :pages end - resources :pages, param: :slug, only: :show, path: "" + resources :pages, param: :slug, only: :show, path: "" do + get "preview" + end resolve("Page") { |page| page_path(page.slug) }