문제

Using faker gem with rails to generate some fake data. When I use faker::lorem the output includes dashes in front of the string.

namespace :db do
  desc "Fill database with sample data"
  task populate: :environment do
    7.times do |l|
      line = Line.create!(sentence: Faker::Lorem.sentences(2))
    end
  end
end

Like:

---
- Odit consectetur perspiciatis delectus sunt quo est.
- Tempore excepturi soluta aliquam perferendis.

Any idea why this function returns the Lorem with dashes? Easiest way to strip them out?

도움이 되었습니까?

해결책

As Kevin and Deefour mention in the comments, Faker::Lorem returns an array.

Since we're asking Ruby to store it in a string, Ruby interprets it per the guidelines for YAML, which is a way of representing data structures in text.

If you're encountering this issue, the simplest fix is to use Ruby's built in array-to-string conversion method .join(x), which takes string x as the delimiter to add.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top