Hi ,

   I need to acheive the result to be as

   result =  [{"first"=>1, "second"=>2}, {"first"=>2, "second"=>3},
{"first"=>3, "second"=>4}, {"first"=>4, "second"=>5}]

  since this hash is the  PDF::SimpleTable.data format

  the table data accepts the hash values with the keys as columns and
the values as the table rows
  In this case i have to create the report from the database records I
have the Array of employee objects with the fields
  I need to put them in table format so that first I have to make the
column names as the table column headings and then need to form a row
of values

 For example my 'employees' contains the employee object
 then, each object has to become one value in the hash


 data = Hash.new
 result = Hash.new
 for employees.each do |record|

 data = {"Sno" =>
record.sno,                                                       Here
i have one record
             "UserName" => record.username,
             "designation" => record.designation,
             "salary" => record.salary }

 result = data,result

 end


I want result should be in the following format
result = [{"Sno" => 1,"UserName" => "ppp","designation" =>
"se","salary" => 10000},{"Sno" => 2,"UserName" => "xxx","designation"
=> "se","salary" => 10000},{"Sno" => 3,"UserName" =>
"yyy","designation" => "se","salary" => 10000},{"Sno" => 4,"UserName"
=> "zzz","designation" => "se","salary" => 10000}]

then I could  replace the table data

table.data.replace result
table.render_on(pdf)

But I am not getting the required format? How to achieve that?

On Nov 25, 2:15 pm, Francois Beuraud <[EMAIL PROTECTED]
s.net> wrote:
> Hema Gonaboina wrote:
> > Hi All,
> >             I need to add the hashes is there any way to add
>
> > actually my data is in the given format
> > data = [ {"first" => 1 ,"second" =>  2},
> >             {"first" => 2 ,"second" =>  3},
> >             {"first" => 3 ,"second" =>  4} ]
>
> > I want to acheive it through the loop So,
>
> Perhaps like this :
>
>  data = []
>  for k in 1..4 do
>  data[k-1] = {"first"=>k , "second"=>k+1}
>  end
>
> HTH
>
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to