From ee4e251450b6e13624f901570b3044303624a636 Mon Sep 17 00:00:00 2001 From: Andras Suller Date: Tue, 22 Mar 2022 17:05:56 +0800 Subject: [PATCH 1/2] Fallback to current dir if Rails.root is nil --- lib/generators/scenic/view/view_generator.rb | 2 +- lib/scenic/definition.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/scenic/view/view_generator.rb b/lib/generators/scenic/view/view_generator.rb index 496035f8..c85339b0 100644 --- a/lib/generators/scenic/view/view_generator.rb +++ b/lib/generators/scenic/view/view_generator.rb @@ -80,7 +80,7 @@ def file_name end def views_directory_path - @views_directory_path ||= Rails.root.join("db", "views") + @views_directory_path ||= (Rails.root || Pathname.new(Dir.pwd)).join("db", "views") end def version_regex diff --git a/lib/scenic/definition.rb b/lib/scenic/definition.rb index 58195107..10bd7b73 100644 --- a/lib/scenic/definition.rb +++ b/lib/scenic/definition.rb @@ -15,7 +15,7 @@ def to_sql end def full_path - Rails.root.join(path) + (Rails.root || Pathname.new(Dir.pwd)).join(path) end def path From c554dd6164f1d75b44b8d8b523d678ed66afa98f Mon Sep 17 00:00:00 2001 From: Andras Suller Date: Tue, 22 Mar 2022 17:06:15 +0800 Subject: [PATCH 2/2] Require scenic in generators I got uninitialized constant error: ``` /Users/andras/projects/scenic/lib/generators/scenic/view/view_generator.rb:99:in `previous_definition': uninitialized constant Scenic::Definition (NameError) ``` The requires fixed the issue for me. --- lib/generators/scenic/model/model_generator.rb | 1 + lib/generators/scenic/view/view_generator.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/generators/scenic/model/model_generator.rb b/lib/generators/scenic/model/model_generator.rb index b04e4186..6afa75f6 100644 --- a/lib/generators/scenic/model/model_generator.rb +++ b/lib/generators/scenic/model/model_generator.rb @@ -1,5 +1,6 @@ require "rails/generators" require "rails/generators/rails/model/model_generator" +require "scenic" require "generators/scenic/view/view_generator" require "generators/scenic/materializable" diff --git a/lib/generators/scenic/view/view_generator.rb b/lib/generators/scenic/view/view_generator.rb index c85339b0..30d68029 100644 --- a/lib/generators/scenic/view/view_generator.rb +++ b/lib/generators/scenic/view/view_generator.rb @@ -1,5 +1,6 @@ require "rails/generators" require "rails/generators/active_record" +require "scenic" require "generators/scenic/materializable" module Scenic