Pages

Friday, August 12, 2016

How to get the Rails app root directory path in Rails console?

You can get the Rails app root directory path in Rails console like this:

rails c
Loading development environment (Rails 5.0.0)
>> Rails.root
=> #
>> Rails.root.class
=> Pathname

You can get any path in your Rails app by using join method:

>> Rails.root.join('app', 'assets')
=> #

You have to call to_s to get a string like this:

>> Rails.root.join('app', 'assets').to_s
=> "/Users/zepho/temp/zurb/app/assets"


No comments:

Post a Comment