I have a template that generates a rails app. The problem is that in my template scenario I substitute some files, like environment.rb, that need to know rails app name to run things like AppName::Application.initialize!
. I could get the app name from the command line arguments, but that's not always possible, since a user could do that: rails new ./
and the app name would be the name of the current dir then, but I would get nothing from the argument list.
So I'd like to know a certain way of getting a Rails app name in a template开发者_高级运维 scenario.
What you're looking for is the app_name
attribute (as George Yacoub suggests).
You can use app_name inside your generator file.
Lots of documentations here http://api.rubyonrails.org/v3.2.14/classes/Rails/Generators/AppGenerator.html#method-i-app_name
and it changed to application_name in rails 4
http://api.rubyonrails.org/classes/Rails/Generators/NamedBase.html#method-i-application_name
精彩评论