How do I access the name of the Rails 3 application object?

后端 未结 8 896
礼貌的吻别
礼貌的吻别 2020-12-23 13:28

I need to know the name of a programmers application from within a Rails 3 engine.

相关标签:
8条回答
  • 2020-12-23 14:11

    In Rails 3, the application that is generated is given a module namespace matching the application name. So if your application was called "Twitter", the class of Rails.application is "Twitter::Application".

    This means that you could split the string of the class name of your Rails application to get an application name like this:

    Rails.application.class.to_s.split("::").first
    

    In our example, the resulting string would be "Twitter".

    0 讨论(0)
  • 2020-12-23 14:12
    Rails.application.class.parent_name
    
    0 讨论(0)
提交回复
热议问题