views:

50

answers:

2

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

+1  A: 

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".

Scott Lowe
A: 

Rails.application returns your MyApp::Application class.

Justice