Skip to content

Commit

Permalink
Add preview route to dummy app frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
sfnelson committed Aug 26, 2024
1 parent 6d4e976 commit d6761a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions spec/dummy/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/dummy/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<h1><%= page.title %></h1>

<%= render_content page.published_version %>
<%= render_content version %>
4 changes: 3 additions & 1 deletion spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit d6761a7

Please sign in to comment.