Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top