Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: no implicit conversion of Pathname into String

Tags:

ruby

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?

like image 992
Peter Penzov Avatar asked Apr 20 '26 09:04

Peter Penzov


1 Answers

Have you tried to do Rails.root.to_s? I guess the problem is that Rails.root is a PathName, not a String, as you can see on the below picture.

enter image description here

You can easily concatenate with the + operator if you cast the Rails.root to String. Please check the below picture.

enter image description here

like image 103
Victor Avatar answered Apr 22 '26 01:04

Victor