diff options
author | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2017-01-04 23:55:15 +0900 |
---|---|---|
committer | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2017-01-07 22:32:53 +0900 |
commit | 4459a18db6fc9294d1f2553e45f59c859602dbad (patch) | |
tree | 1028c3f98dac9c12f881bc44459c7766be192d5a /railties/lib | |
parent | 7b13236818ffb26e94d72885e75966efffd71659 (diff) | |
download | rails-4459a18db6fc9294d1f2553e45f59c859602dbad.tar.gz rails-4459a18db6fc9294d1f2553e45f59c859602dbad.tar.bz2 rails-4459a18db6fc9294d1f2553e45f59c859602dbad.zip |
Fix generator command for nested (namespaced) rails engine (take 2)
Rewrite https://github.com/rails/rails/pull/27550
085546df45 was reverted (b6ffb5efcb) because it change the return of `namespaced_path` from String to Array.
----------------
If we create nested (namespaced) rails engine such like bukkits-admin,
`bin/rails g scaffold User name:string age:integer`
will create
`bukkits-admin/app/controllers/bukkits/users_controller.rb`
but it should create
`bukkits-admin/app/controllers/bukkits/admin/users_controller.rb`.
In #6643, we changed `namespaced_path` as root path
because we supposed application_controller is always in root
but nested rails engine's application_controller will not.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/named_base.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 6f1925928b..02557b098a 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -82,6 +82,10 @@ module Rails !options[:skip_namespace] && namespace end + def namespace_dirs + @namespace_dirs ||= namespace.name.split("::").map(&:underscore) + end + def file_path # :doc: @file_path ||= (class_path + [file_name]).join("/") end @@ -95,11 +99,11 @@ module Rails end def namespaced_class_path # :doc: - @namespaced_class_path ||= [namespaced_path] + @class_path + @namespaced_class_path ||= namespace_dirs + @class_path end def namespaced_path # :doc: - @namespaced_path ||= namespace.name.split("::").first.underscore + @namespaced_path ||= namespace_dirs.join("/") end def class_name # :doc: diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index 8840a86d0d..292db35121 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -22,7 +22,7 @@ module TestUnit # :nodoc: def fixture_name @fixture_name ||= if mountable_engine? - "%s_%s" % [namespaced_path, table_name] + (namespace_dirs + [table_name]).join("_") else table_name end |