Reputation: 7361
I know we can generate fake data with faker in Ruby.
I want to send fake data from the API in the response. Currently, I generated a dummy response in the public/data.json
file which has only three static objects.
def dummy_response
data = File.read("#{Rails.root}/public/data.json")
render :json => data, status: 200
end
I have to send 100 dummy objects with random values. Can I use the yml
file to send dummy data or with faker gem generate dummy JSON and send it back in response?
Upvotes: 1
Views: 1043
Reputation: 6942
You could do something like this:
data_hash = {}
100.times { |x| data_hash[x] = { name: Faker::Name.first_name } }
render json: data_hash.to_json, status: 200
Upvotes: 1