开发者

get Rails3 app name in a template that generates a rails app?

开发者 https://www.devze.com 2023-01-05 13:48 出处:网络
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::App

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号