|
|
|||
Rails Activerecord getdata
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 detail. and got undefined method `programCode' for #<Array:0x00000100ec9338> 1 Reply
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| d.programCode [put here all you need do with this data] end 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. cjapes |
|||
|