From 72f76cd420454513ac0e687aa5b48e4108de69a6 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 3 Sep 2024 19:09:57 +0200 Subject: [PATCH] Set Alchemy::Page.current in Messages Controller Since Alchemy 7.2 (#2701) we need to set `Alchemy::Page.current` if we want to render a page from another controller. (cherry picked from commit 19b2b34aa32e090ef68531d259ccb6e1f910a8e2) --- app/controllers/alchemy/messages_controller.rb | 1 + spec/controllers/alchemy/messages_controller_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/controllers/alchemy/messages_controller.rb b/app/controllers/alchemy/messages_controller.rb index 321d3e5e64..b84ac401d2 100644 --- a/app/controllers/alchemy/messages_controller.rb +++ b/app/controllers/alchemy/messages_controller.rb @@ -66,6 +66,7 @@ def create # :nodoc: MessagesMailer.contact_form_mail(@message, mail_to, mail_from, subject).deliver redirect_to_success_page else + Current.page = @page render template: "alchemy/pages/show" end end diff --git a/spec/controllers/alchemy/messages_controller_spec.rb b/spec/controllers/alchemy/messages_controller_spec.rb index 72a10bc7ec..26aa25004c 100644 --- a/spec/controllers/alchemy/messages_controller_spec.rb +++ b/spec/controllers/alchemy/messages_controller_spec.rb @@ -56,6 +56,11 @@ module Alchemy it "should render 'alchemy/pages/show' template" do expect(subject).to render_template("alchemy/pages/show") end + + it "assigns Alchemy::Page.current" do + expect(Alchemy::Current).to receive(:page=).with(page) + subject + end end context "succeeded" do