Skip to content

Commit c622c7a

Browse files
refactor shared data method
1 parent a9cb801 commit c622c7a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

lib/inertia_rails/controller.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ def default_render
6060
end
6161

6262
def shared_data
63-
# Theses variables are set in the before_action, but we need to ensure they are initialized when using renderer alone
64-
@_inertia_shared_plain_data ||= {}
65-
@_inertia_shared_blocks ||= []
66-
67-
@_inertia_shared_plain_data.merge(evaluated_blocks)
63+
(@_inertia_shared_plain_data || {}).merge(evaluated_blocks)
6864
end
6965

7066
def redirect_to(options = {}, response_options = {})
@@ -108,7 +104,7 @@ def capture_inertia_errors(options)
108104
end
109105

110106
def evaluated_blocks
111-
@_inertia_shared_blocks&.map { |block| instance_exec(&block) }&.reduce(&:merge) || {}
107+
(@_inertia_shared_blocks || []).map { |block| instance_exec(&block) }.reduce(&:merge) || {}
112108
end
113109
end
114110
end

0 commit comments

Comments
 (0)