Rails: What is the correct usage of Rails.root.join when pointing to "tmp/caching-dev.txt"?

Viewed 5255

I'm setting up a new Rails project and after giving it an initial tidy with Rubocop, I'm left with a single offense.

Rubop complains:

config/environments/development.rb:16:6: C: Please use Rails.root.join('path', 'to') instead.
  if Rails.root.join("tmp/caching-dev.txt").exist?

I see that Rails.root returns the path of the current project. So I've tried

if File.join(Rails.root, "tmp/caching-dev.text").exist?

instead. But still, Rubocop complains:

config/environments/development.rb:17:6: C: Please use Rails.root.join('path', 'to') instead.
  if File.join(Rails.root, "tmp/caching-dev.text").exist?
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What are the path and root arguments meant to be? Surely Rails.root is the path?!

3 Answers

I think Rubocop is suggesting you to do something like this

if File.exist?(Rails.root.join('tmp', 'caching-dev.txt'))

IMHO, Pathname and / are not used enough.

if (Rails.root / 'tmp' / 'caching-dev.txt').exist?

I solved problem by config .rubocop.yml:

Style/ExpandPathArguments: EnforcedStyle: Style/ExpandPathArguments Enabled: false

Related