Kendall Gifford wrote in post #991124:
> Have you tried adding:
>
>   StaticDataGenerator.new.posts!
>
> to the end of your file?

Thanks for response. yes, that worked. That makes sense that you need to 
call a method in client code for it to do anything. I do have one 
unexpected result. This method right here:

  def posts!
    Title.each do |t|
      Body.each do |b|
        post! t, b, @current_user.id
      end
    end
  end


I was expecting it to generate a combination like this:
"ABC" "MNO"
"DEF" "PQR"
"GHI" "STU"
"JKL" "VWX"


See how it corresponds index 0 of the Title array with index 0 of the 
Body array and then index 1 of the Title array with index 1 of the Body 
array and so forth.

But what my posts! method does is this:

"ABC" "MNO"
"ABC" "PQR"
"ABC" "STU"
"ABC" "VWX"
"DEF" "MNO"
"DEF" "PQR"
"DEF" "STU"
"DEF" "VWX"

and so forth. See how it generates index 0 of Title with all the indexes 
of Body and does it for the other indexes of Title as well.

I believe it's my misunderstanding of the nested block:

   Title.each do |t|
      Body.each do |b|
        post! t, b, @current_user.id
      end
    end

I thought this would iterate through the first index of Title as local 
variable t and then iterate through first index of Body as local 
variable b and then pass them into argument list of post! And then when 
the outer block ended, it would go to the next index and repeat same 
process

Anyone know what I am doing wrong and how to get it to match index to 
index not index to all the other indexes?

Thanks for response.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to