Hi evrybody.. I was storing the values in hash using.. places = [ {:address=>''555 Irving, San Francisco, CA'',:description=>''Irving'',:image=>''/images/1.jpg''}, {:address=>''1401 Valencia St, San Francisco, CA'',:description=>''Valencia'',:image=>''/images/2.jpg''}, ] But now I want to take these values from database..I created , migrated table correctly... N now using the statement @companies = Company.find(:all) But now i dont understand how can i store these fetched values in hash-> ''places''I dont want static values... So can anybody please help me for it... Thanks... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Vrishali.... wrote:> N now using the statement > @companies = Company.find(:all) > > > But now i dont understand how can i store these fetched values in hash- >> ''places'' > > I dont want static values...I''m not quite sure why you need to store the values from the ActiveRecords in a hash, but basically ActiveRecord uses a hash, or something like a hash, internally and it''s easy to get to that using the attributes method: places = [] @companies.each do |company| places << company.attributes end This will build an array of hashes just like what you had with the static values. But, like I said I don''t know why you would need to do this. You could just use the ActiveRecords directly. And if you wanted a serialized version of them for some reason then JSON is a good format for that: @companies.to_json -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the help... actually i am using places hash evrywhere....so i dnt want modifications throughout the code...n files...so..i want to put the all retrieved records to be placed in that...places. n i want it at the start of controller call... thats y... ok i tried ur statments given...but still it is giving error... TypeError in GmapController#index can''t convert nil into String RAILS_ROOT: /home/ubuntu/gmaptry Application Trace | Framework Trace | Full Trace app/controllers/gmap_controller.rb:57:in `+'' app/controllers/gmap_controller.rb:57:in `get_geocode'' app/controllers/gmap_controller.rb:30:in `index'' app/controllers/gmap_controller.rb:28:in `each'' app/controllers/gmap_controller.rb:28:in `each_with_index'' app/controllers/gmap_controller.rb:28:in `index'' .... so what should i do...please help.... also i am using evrywhere.... place[:address] place[:description].... so how can i specify that... please help me.... thanks... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok... I got the solution by myself now i am using the code... @companies.each do |company| places [ {:address => company.addr, :description => company.cname , :image => company.img}] end it is working without ant error... but now the problem is that ..... the values are getting overwritted in places array...and only last record is saved... so what can i do for increamenting places index... or anybody knows any another method.... please help me.... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---