DEV Community


Explore files under a specific directory in Rails

konyu profile image @kon_yu ・1 min read

If you want to recursively retrieve the file paths under a particular directory, you can use the
Use the Dir class to get the path.

If you want to call it in Rails, you can use Rails.root to get the absolute path where Rails is running on the OS you're running, so you don't have to lead the production or development environment.

execution example

Dir.glob("#{Rails.root}/app/models/**/*") do |f
  p f

=> "/var/app/models/user.rb"

Discussion (0)

Editor guide