That's great it worked fine
But I have another problem,

please check the code

Fields = Array.new
Fields [0] = "sno"
Fields [1] = "username"
Fields [2] = "designation"
Fields [3] = "salary"
Fields [4] = "dob"
Fields [5] = "email"
Fields [6] = "doj"


These are the fields of the object 'Employee'

The Employees array contains of the set of employee objects...

I need to have the array of hashes as [{employee_record1},
{employee_record2}...... n records]

For this i tried as the...


result = []

for employee in Employees
res = {}
    for field in fields
      res << { field => employee.send(field)}
   end
result << res
end


But it is not working... Please Help me Thank You



On Nov 26, 12:23 pm, Pradeep Gatram <[EMAIL PROTECTED]> wrote:
> Think in terms of the domain. What you need is an array of hashes.
> Each hash is a representation of your domain object (employee record)
>
> employees.collect {|employee| employee.attributes}
>
> Thats it.
>
> If there are any particular attributes that you don't want, e.g.
> created_at, then use something like
>
> employees.collect {|employee| employee.attributes.except(:created_at)}
--~--~---------~--~----~------------~-------~--~----~
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