faker gem for Blog and comment

Hi, how do I push fake data with faker when I have:

blog

title:string

and

comment

name:string

body:text_field

comments belongs_to :blog

then seed.rb:

5.times do

comment.create([{

name: Faker::jadajada

body: Faker::jadajada

}])

but how do I include blog title as well? There should be some kind of nesting?

What exactly are you trying to accomplish? "include" where?

I want to populate data between 2 models (blog title and comment body). In my example “5.times do…” I’m populating fake data only for my comment model. How do I populate for both?

I want to populate data between 2 models (blog title and comment body). In
my example "5.times do..." I'm populating fake data only for my comment
model. How do I populate for both?

Create the blog with its title and add the comments to the blog. If
you want separate blogs for each comment then put that inside the loop
so you create five blogs and comments.

Colin

How should the loop look like?

5 times do…

???

How should the loop look like?

5 times do...

???

You know how to create a comment so presumably you can work out how to
create a blog. Do you mean you don't know how to add the comment to
the blog? This should help, choose the way you want from the several
described in http://guides.rubyonrails.org/association_basics.html#has-many-association-reference.
It is probably worth your while looking through all the guides.

In fact since it seems you are a beginner I suggest working right
through a good tutorial such as railstutorial.org, which is free to
use online.

Colin

Thanks for the info but this is not the case. I already have a blog, with comments etc. My main question is: how to use ‘faker’ gem to populate data for blog title and comment body? What code should I put in seed.rb?

i.e:

5.times do ([{

what code do I need to put here??

}])

OK, you say you already have a blog. Let us take this one step at a
time. You say you want to set the blog title. Assuming that you have
the blog in a variable called theblog then you can set the title using
theblog.title = Faker:whatever

What is it that you don't understand with that?

By the way I would prefer it if you did not top post, it makes it much
easier for me to follow the thread if you insert your reply at
appropriate points in the previous message. Thanks.

Colin