Jump to content

Rails Activerecord getdata

itsmeonly's Photo
Posted Dec 06 2010 10:29 AM

I am new to ROR.
I am trying to get some data from the database and use it in my functions.

I do the following in the controller
detail = Detail.find(:all, :conditions => ['program LIKE ?', "%#{search}%"])

I get the result back as
[#<Detail id: 2, program: "New Program 1", programCode: 11222, program_manager: "Micheal", program_manager_email: "test@test.com", created_at: "2010-12-03 18:51:42", updated_at: "2010-12-03 18:51:42">]

I need to be able to use the program and programCode to create a document.
How do I separate out the data
I tried to do
and got
undefined method `programCode' for #<Array:0x00000100ec9338>

0 Subscribe

1 Reply

+ 1
  cjapes's Photo
Posted Jan 18 2011 05:50 AM

Because it is a multidimensional array.

if you want just the first record try doing this: detail.first.programCode

or if you need to go through all programCode your query gives you you can do:

detail.each do |d|

[put here all you need do with this data]


this will go through all the records your query gives you and one by one all of them will be inside "d".

Hope this helps.