faker gem for Blog and comment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

faker gem for Blog and comment

k.stulgys
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?







--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fbfd0b3d-fabb-433d-a505-1dd8bf76868a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

Hassan Schroeder-2
On Wed, Jul 26, 2017 at 11:15 PM,  <[hidden email]> wrote:

> then seed.rb:
>
> 5.times do
>   comment.create([{
>     name: Faker::jadajada
>     body: Faker::jadajada
> }])
>
> but how do I include blog title as well?

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

--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yDY4P748-dFuhgXZvA6AN2gU%3DgCiXMmDLfX%3DUM7KtO7gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

k.stulgys
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?

On Friday, July 28, 2017 at 1:48:49 AM UTC+10, Hassan Schroeder wrote:
On Wed, Jul 26, 2017 at 11:15 PM,  <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="vmt1BFW7AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">k.st...@...> wrote:

> then seed.rb:
>
> 5.times do
>   comment.create([{
>     name: Faker::jadajada
>     body: Faker::jadajada
> }])
>
> but how do I include blog title as well?

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

--
Hassan Schroeder ------------------------ <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vmt1BFW7AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">hassan.s...@...
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5339c5e1-df60-4026-9157-73c28b28ccca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

Colin Law
On 28 July 2017 at 01:10,  <[hidden email]> wrote:
> 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

>
> On Friday, July 28, 2017 at 1:48:49 AM UTC+10, Hassan Schroeder wrote:
>>
>> On Wed, Jul 26, 2017 at 11:15 PM,  <[hidden email]> wrote:
>>
>> > then seed.rb:
>> >
>> > 5.times do
>> >   comment.create([{
>> >     name: Faker::jadajada
>> >     body: Faker::jadajada
>> > }])
>> >
>> > but how do I include blog title as well?
>>
>> What exactly are you trying to accomplish? "include" where?
>>
>> --
>> Hassan Schroeder ------------------------ [hidden email]
>> twitter: @hassan
>> Consulting Availability : Silicon Valley or remote
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/5339c5e1-df60-4026-9157-73c28b28ccca%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuDtRkvedUEM9XGrKbHHKefQuTF2fMB59ynT5HMa8MJew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

k.stulgys
How should the loop look like?

5 times do...

???

On Fri, Jul 28, 2017 at 5:59 PM, Colin Law <[hidden email]> wrote:
On 28 July 2017 at 01:10,  <[hidden email]> wrote:
> 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

>
> On Friday, July 28, 2017 at 1:48:49 AM UTC+10, Hassan Schroeder wrote:
>>
>> On Wed, Jul 26, 2017 at 11:15 PM,  <[hidden email]> wrote:
>>
>> > then seed.rb:
>> >
>> > 5.times do
>> >   comment.create([{
>> >     name: Faker::jadajada
>> >     body: Faker::jadajada
>> > }])
>> >
>> > but how do I include blog title as well?
>>
>> What exactly are you trying to accomplish? "include" where?
>>
>> --
>> Hassan Schroeder ------------------------ [hidden email]
>> twitter: @hassan
>> Consulting Availability : Silicon Valley or remote
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/5339c5e1-df60-4026-9157-73c28b28ccca%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/9bpSWyqujtM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuDtRkvedUEM9XGrKbHHKefQuTF2fMB59ynT5HMa8MJew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFNzrsedh4%3D-_CGFW8O1D%3DbFu01xjvFWUSiVOTVfwJgovoVeZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

Colin Law
On 29 July 2017 at 07:55, K S <[hidden email]> wrote:
> 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

>
> On Fri, Jul 28, 2017 at 5:59 PM, Colin Law <[hidden email]> wrote:
>>
>> On 28 July 2017 at 01:10,  <[hidden email]> wrote:
>> > 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
>>
>> >
>> > On Friday, July 28, 2017 at 1:48:49 AM UTC+10, Hassan Schroeder wrote:
>> >>
>> >> On Wed, Jul 26, 2017 at 11:15 PM,  <[hidden email]> wrote:
>> >>
>> >> > then seed.rb:
>> >> >
>> >> > 5.times do
>> >> >   comment.create([{
>> >> >     name: Faker::jadajada
>> >> >     body: Faker::jadajada
>> >> > }])
>> >> >
>> >> > but how do I include blog title as well?
>> >>
>> >> What exactly are you trying to accomplish? "include" where?
>> >>
>> >> --
>> >> Hassan Schroeder ------------------------ [hidden email]
>> >> twitter: @hassan
>> >> Consulting Availability : Silicon Valley or remote
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Ruby on Rails: Talk" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [hidden email].
>> > To post to this group, send email to [hidden email].
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/rubyonrails-talk/5339c5e1-df60-4026-9157-73c28b28ccca%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Ruby on Rails: Talk" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/rubyonrails-talk/9bpSWyqujtM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [hidden email].
>> To post to this group, send email to [hidden email].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuDtRkvedUEM9XGrKbHHKefQuTF2fMB59ynT5HMa8MJew%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/CAFNzrsedh4%3D-_CGFW8O1D%3DbFu01xjvFWUSiVOTVfwJgovoVeZg%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs6m_k%3DF5UdXLVGqBw1HyiArSfjSxOaR6J1CmnZYn7MOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

k.stulgys
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??

}])


On Sat, Jul 29, 2017 at 5:16 PM, Colin Law <[hidden email]> wrote:
On 29 July 2017 at 07:55, K S <[hidden email]> wrote:
> 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

>
> On Fri, Jul 28, 2017 at 5:59 PM, Colin Law <[hidden email]> wrote:
>>
>> On 28 July 2017 at 01:10,  <[hidden email]> wrote:
>> > 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
>>
>> >
>> > On Friday, July 28, 2017 at 1:48:49 AM UTC+10, Hassan Schroeder wrote:
>> >>
>> >> On Wed, Jul 26, 2017 at 11:15 PM,  <[hidden email]> wrote:
>> >>
>> >> > then seed.rb:
>> >> >
>> >> > 5.times do
>> >> >   comment.create([{
>> >> >     name: Faker::jadajada
>> >> >     body: Faker::jadajada
>> >> > }])
>> >> >
>> >> > but how do I include blog title as well?
>> >>
>> >> What exactly are you trying to accomplish? "include" where?
>> >>
>> >> --
>> >> Hassan Schroeder ------------------------ [hidden email]
>> >> twitter: @hassan
>> >> Consulting Availability : Silicon Valley or remote
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Ruby on Rails: Talk" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [hidden email].
>> > To post to this group, send email to [hidden email].
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/rubyonrails-talk/5339c5e1-df60-4026-9157-73c28b28ccca%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Ruby on Rails: Talk" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/rubyonrails-talk/9bpSWyqujtM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [hidden email].
>> To post to this group, send email to [hidden email].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuDtRkvedUEM9XGrKbHHKefQuTF2fMB59ynT5HMa8MJew%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/CAFNzrsedh4%3D-_CGFW8O1D%3DbFu01xjvFWUSiVOTVfwJgovoVeZg%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/9bpSWyqujtM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs6m_k%3DF5UdXLVGqBw1HyiArSfjSxOaR6J1CmnZYn7MOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFNzrseChMqv7kNQzt_8A%3D7ByVNN0kFxi-q%3DdWpooSdvNxGsmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: faker gem for Blog and comment

Colin Law
On 1 August 2017 at 07:17, K S <[hidden email]> wrote:
> 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?

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuwmyjZfLPG3WNnCJeLPvCgnGs26NhK2qFgrDLKwpS-NA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...