TypeError: no implicit conversion of Pathname into String

0 votes
asked Sep 12, 2017 by peter-penzov

I want to use this code to run rake task:

task :backup_and_delete_old_data => :environment do
      if defined?(Rails)
        require Rails.root + '/config/boot'
      else
        require '../../../config/boot'
      end
      require Rails.root + '/config/environment'

      factory_backup.each do |factory_data|
        puts ">> Backup and delete old #{factory_data.to_s.pluralize.humanize} data..."
        factory_data.factory_backup(backup_and_delete_old_data)
      end
    end

But when I run the rake task I get error:

TypeError: no implicit conversion of Pathname into String

for this line:

require Rails.root + '/config/boot'

Do you know how I can fix this issue?

1 Answer

0 votes
answered Sep 12, 2017 by mohanraj

You have use the below format to require a ruby file,

require File.expand_path('../../../config/environment',  __FILE__)

Please specify correct ../ to correct location of file.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...