How do I get my Rails app's root directory path?
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
|
In Rails 3 and newer:
which returns a
In Rails 2 you can use the |
|||||||||||||||||
|
|
For super correctness, you should use:
which will allow your app to work on platforms where |
|||||
|
|
You can access rails app path using variable For example:
|
|||||
|
|
In addition to all the other correct answers, since
You could use something like
If you want a string use this:
|
|||||||||
|
|
In some cases you may want the Rails root without having to load Rails. For example, you get a quicker feedback cycle when TDD'ing models that do not depend on Rails by requiring
Which allows you to easily load Plain Old Ruby Objects from their spec files.
|
|||
|
|
|
You can use:
But to to join the assets you can use:
Hopefully this helps you. |
||||
|
|
|
Simply by Rails.root or if you want append something we can use it like Rails.root.join('app', 'assets').to_s |
|||||
|
|
Simply By writing Rails.root and append anything by Rails.root.join(*%w( app assets)).to_s |
|||||
|