Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
52
Help us understand the problem. What is going on with this article?
@munaita_

Railsのファイルパスの操作のメモ

More than 1 year has passed since last update.

毎回ググっているのでメモ

プロジェクトルートパスの取得

Rails.root.to_s
# => "/Users/user_name/Documents/workspace/ruby/project_name"

現在の実行ファイルのパス

__FILE__
# => "/Users/user_name/Documents/workspace/ruby/project_name/spec/exec_file.rb"

ディレクトリの取得

Rails.root.dirname
# => "/Users/user_name/Documents/workspace/ruby"
File.dirname(__FILE__)
# => "/Users/user_name/Documents/workspace/ruby/project_name/spec”

パスの加工

Rails.root.join('hoge', 'huga').to_s
# =>"/Users/user_name/Documents/workspace/ruby/project_name/hoge/fuga"
File.expand_path('../../shared/log/unicorn.log', Rails.root)
# => "/Users/user_name/Documents/workspace/shared/log/unicorn.log”
52
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
munaita_
フリーランスのデータエンジニアです。 データ基盤構築や、ビッグデータを扱うシステム構築が得意です。 新卒サイバーエージェントからフリーランス。 広告/小売/教育など幅広いドメインのデータビジネスを経験しています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
52
Help us understand the problem. What is going on with this article?