Closed thedumbtechguy closed 2 months ago
Got it to work with this
diff --git a/template.rb b/template.rb
index 370ff35..caed642 100644
--- a/template.rb
+++ b/template.rb
@@ -92,6 +92,10 @@ class DatabaseYAML
end
end
+def find_in_application(path)
+ File.expand_path(Rails.root.join(path))
+end
+
# ------------------------------------------------------------------------------
# Ensure all SQLite connections are properly configured
@@ -115,7 +119,7 @@ unless SKIP_SOLID_QUEUE
end
# 3. define the new database configuration
- database_yaml = DatabaseYAML.new path: find_in_source_paths("config/database.yml")
+ database_yaml = DatabaseYAML.new path: find_in_application("config/database.yml")
insert_into_file "config/database.yml",
database_yaml.new_database(QUEUE_DB) + "\n",
after: database_yaml.database_def_regex("default"),
@@ -201,7 +205,7 @@ unless SKIP_SOLID_CACHE
end
# 3. define the new database configuration
- database_yaml = DatabaseYAML.new path: find_in_source_paths("config/database.yml")
+ database_yaml = DatabaseYAML.new path: find_in_application("config/database.yml")
insert_into_file "config/database.yml",
database_yaml.new_database(CACHE_DB) + "\n",
after: database_yaml.database_def_regex(QUEUE_DB)
new diff
diff --git a/template.rb b/template.rb
index 4de1170..da8dd1f 100644
--- a/template.rb
+++ b/template.rb
@@ -92,6 +92,11 @@ class DatabaseYAML
end
end
+def find_in_application(path)
+ require "fileutils"
+ in_root { File.expand_path(path, FileUtils.pwd) }
+end
+
# ------------------------------------------------------------------------------
# Ensure all SQLite connections are properly configured
I meant try this:
full_path = in_root { find_in_source_paths("config/database.yml") }
database_yaml = DatabaseYAML.new full_path
It didn't work.
The source paths do not include the application root as listed here
Caused by:
Thor::Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are: (Thor::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates
Try simply adding readme "config/database.yml"
to the script and see if that errors
user@C02YV2TVLVCF tall_mast % bin/rails app:template \
LOCATION=/Users/user/Desktop/enlitenment-main/template.rb
=> [plutonium] starting reloader
apply /Users/user/Desktop/enlitenment-main/template.rb
bin/rails aborted!
Rails::Generators::Error: The template [/Users/user/Desktop/enlitenment-main/template.rb] could not be loaded. Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are: (Rails::Generators::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates
Caused by:
Thor::Error: Could not find "config/database.yml" in any of your source paths. Your current source paths are: (Thor::Error)
/Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.2.0/lib/rails/generators/rails/app/templates
Tasks: TOP => app:template
(See full trace by running task with --trace)
And ?
in_root { readme "config/database.yml" }
Ps. Thanks a ton for experimenting for me
Same error
Are you suspecting that the rails treats the app root as a source directory for templates? Does it do that on fresh install maybe?
Can you add puts destination_root
into the template and tell me what (if it executes) it outputs. We might need full_path = File.expand_path(path, destination_root)
I am hopeful that this new commit will fix the issue. Can you give the new template a try: https://github.com/fractaledmind/enlitenment/commit/024e262931982f00979b7570722068bb1fc40ce1
destination_root
outputs the correct path.
Confirmed that the change to destination_root
fixes the problem
Perfect.
Describe the bug This occurs immediately after running the template.
I am running a rails 7.2 application.
It fails to find my
database.yml
file.It exists as expected here.
It added 2 gems to my Gemfile
To Reproduce
Expected behavior
N/A
Additional context
Output of the execution.