Skip to content

Commit d4d9879

Browse files
committed
Removing static_files warnings in Rails 5
Issue #19
1 parent f865a92 commit d4d9879

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/models/no_cms/blocks/block.rb

+22-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,28 @@ def fields_configuration
5555
##
5656
# If we don't have a globalized model yet we return our temporary layout
5757
def layout
58-
globalized_model.nil? ? @layout : globalized_model.layout
58+
# Since respond_to_missing? has been reimplemented in
59+
# NoCms::Blocks::Concerns::SerializingFields we need to first check that
60+
# we have the foreign key to access the globalized_model association
61+
#
62+
# This is due to the empty translations Globalize creates sometimes that
63+
# only have locale.
64+
#
65+
# If we don't check then we will throw a non defined attribute
66+
# exception.
67+
68+
# First we check wether we don't respond to the foreign key of the
69+
# globalize model association
70+
if !respond_to?(self.class.reflections.symbolize_keys[:globalized_model].foreign_key) ||
71+
globalized_model.nil? # and then that the globalized model is nil
72+
73+
# In any of these cases we return our stored layout
74+
@layout
75+
else
76+
# If we can access to the globalized_model, then we return its
77+
# information
78+
globalized_model.layout
79+
end
5980
end
6081

6182
include NoCms::Blocks::Concerns::SerializingFields

spec/dummy/config/environments/test.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313
config.eager_load = false
1414

1515
# Configure static asset server for tests with Cache-Control for performance.
16-
config.serve_static_files = true
17-
config.static_cache_control = "public, max-age=3600"
16+
if Rails.version > "5"
17+
config.public_file_server.enabled = true
18+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
19+
else
20+
config.serve_static_files = true
21+
config.static_cache_control = "public, max-age=3600"
22+
end
1823

1924
# Show full error reports and disable caching.
2025
config.consider_all_requests_local = true

0 commit comments

Comments
 (0)