I have a standard has_many/belongs_to relationship with movies and posters. Each movie can have many posters. I have the following in a rake command:
task remove_movie_posters: :environment do
destroyed = Movie.where(fake: true).posters.where("created_at < ?", 1.minute.ago).destroy_all
puts "Done. " + destroyed.length + " records deleted."
end
but I get the error: TypeError: no implicit conversion of Fixnum into String
destroy_all
returns an integer and you cannot concatinate strings and integers like that. A simple example to show this problem is:The solution is to use string interpolation (or the
to_s
method, but that feels ugly to me):