diff --git a/lib/scenic/definition.rb b/lib/scenic/definition.rb index 58195107..aa01b686 100644 --- a/lib/scenic/definition.rb +++ b/lib/scenic/definition.rb @@ -19,7 +19,23 @@ def full_path end def path - File.join("db", "views", filename) + default_view_path = File.join("db", "views") + view_filename = filename + # in version7 of ActiveRecord was removed ActiveRecord::Base.connection_config + custom_paths = if ActiveRecord::VERSION::MAJOR < 7 + ActiveRecord::Base.connection_config[:scenic_views_paths] + else + ActiveRecord::Base.connection_db_config.configuration_hash[:scenic_views_paths] + end + view_paths = Array(custom_paths) + view_paths = [default_view_path] if view_paths.empty? + + full_view_path = nil + view_paths.each do |path| + full_view_path = File.join(path, view_filename) + break if File.exist?(full_view_path) + end + full_view_path end def version diff --git a/lib/scenic/version.rb b/lib/scenic/version.rb index 4c87f6e7..1372370e 100644 --- a/lib/scenic/version.rb +++ b/lib/scenic/version.rb @@ -1,3 +1,3 @@ module Scenic - VERSION = "1.7.0".freeze + VERSION = "1.7.3".freeze end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 5f43185a..aa461f9c 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -12,3 +12,6 @@ development: &default test: <<: *default database: dummy_test +# set custom paths for scenic views +# scenic_views_paths: +# - '/db/views/postges'