Skip to content

Commit cb903e3

Browse files
committed
fixed view context and route helper access on component rendering without controller
1 parent c25e5cb commit cb903e3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/matestack/ui/core/base.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ def params
8585
end
8686

8787
def view_context
88-
Matestack::Ui::Core::Context&.controller&.view_context
88+
if Matestack::Ui::Core::Context.controller.nil?
89+
Matestack::Ui::Core::Context.controller = ActionController::Base.new
90+
else
91+
Matestack::Ui::Core::Context.controller&.view_context
92+
end
8993
end
9094

9195
def method_missing(name, *args, &block)
9296
return view_context.send(name, *args, &block) if view_context && view_context.respond_to?(name, true)
97+
return Rails.application.routes.url_helpers.send(name, *args, &block) if Rails.application.routes.url_helpers.respond_to?(name, true)
9398
return raise NameError, "#{name} is not defined for #{self.class}", caller
9499
end
95100

0 commit comments

Comments
 (0)