0

Hey we are 3 students, we all use the same rails db:seed. Our project is well git pulled and coordinated, but ..

One uses Linux, the rails:db:seed works for him.

One uses Mac, the rails:db:seed works for him too.

Me, I use WSL, and it dosnt work ! I've tried both Windows & WSL paths, as the screens bellow.

Thanks if anyone can guide me !

Error

.env

path

path2

config/seed.rb

# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
#   movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
#   Character.create(name: 'Luke', movie: movies.first)

require 'faker'

RealEstate.destroy_all
User.destroy_all
Category.destroy_all

Category.create(title:"House")
Category.create(title:"Flat")

10.times do
  u = User.create(email: Faker::Internet.email, password: Faker::Internet.password)
end

30.times do
  re = RealEstate.create(
    title: Faker::Space.galaxy, 
    description: Faker::Lorem.paragraph_by_chars(number: 256), 
    address: Faker::Address.full_address, 
    location: Faker::Address.city, 
    price: Faker::Number.number(digits: 8), 
    user: User.all.sample(), 
    category: Category.all.sample()
    )
  re.images.attach(io: File.open(ENV['SAMPLE_IMAGES']), filename: 'sample_image')
end

puts "%" * 50
puts "       Base de données remplie !"
puts "%" * 50

2 Answers 2

1

Resolved !

I actually went to the folder where the file was stocked and simply typed " pwd " :

So, in my case the pathname was : '/home/pedrofromperu/next/images/indian.jpg'

0

This issue you are experiencing happens to lots of people who switch between Unix-Like and Windows operating systems. Paths in Windows are written using ‘\’ instead of ‘/‘. This is particularly confusing when using WSL and PowerShell in windows terminal - you have to keep track of which shell environment you are using. Congrats using ‘print working directory’, pwd, to solve the problem.

One thing you could do if you change environments a lot, (and this is just one approach.) Use the OS gem like so:

require 'os'

OS.windows? # returns true or false.

You could then either provide different paths or get fancy and replace the characters in your string.

Not the answer you're looking for? Browse other questions tagged or ask your own question.