【问题标题】:Rails : Pathname issue with WSLRails:WSL 的路径名问题
【发布时间】:2021-09-08 15:21:27
【问题描述】:

嘿,我们是 3 名学生,我们都使用相同的 rails db:seed。我们的项目很好地被 git 拉动和协调,但是..

一个人使用 Linuxrails:db:seed 适合他。

一个人使用 Macrails:db:seed 也适用于他。

我,我使用 WSL,但它不起作用! 我已经尝试过 Windows 和 WSL 路径,如下面的屏幕所示。

如果有人可以指导我,谢谢!

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

【问题讨论】:

    标签: ruby-on-rails windows-subsystem-for-linux


    【解决方案1】:

    解决了!

    我实际上去了存放文件的文件夹并简单地输入了“pwd”:

    所以,在我的例子中,路径名是:'/home/pedrofromperu/next/images/indian.jpg'

    【讨论】:

      【解决方案2】:

      您遇到的这个问题发生在许多在类 Unix 和 Windows 操作系统之间切换的人身上。 Windows 中的路径使用“\”而不是“/”编写。在 Windows 终端中使用 WSL 和 PowerShell 时,这尤其令人困惑——您必须跟踪您正在使用的 shell 环境。恭喜使用“打印工作目录”pwd 解决问题。

      如果您大量更改环境,您可以做一件事,(这只是一种方法。)像这样使用操作系统 gem:

      require 'os'
      
      OS.windows? # returns true or false.
      

      然后,您可以提供不同的路径,或者花哨并替换字符串中的字符。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多