ruby on rails - How to put and split Hash into database? -


i need put data database.

i have array of hashes:

{:date=>#<date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>, :name=>"capodanno", :regions=>[:it]} {:date=>#<date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>, :name=>"new year'sday", :regions=>[:au, :be, :ca, :nyse]} {:date=>#<date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>, :name=>"new year'sday", :regions=>[:us, :ups]} {:date=>#<date: 2014-04-18 ((2456766j,0s,0n),+0s,2299161j)>, :name=>"good friday", :regions=>[:au, :ca, :gb, :federal_reserve, :nyse, :nz, :za]} {:date=>#<date: 2014-11-11 ((2456973j,0s,0n),+0s,2299161j)>, :name=>"remembrance day", :regions=>[:ca]} 

i need split it, , put a few databases , idea how should done. enter image description here

i tried this:

require 'holidays'  y=2000 holidays.load_all while(y<2070)     = date.civil(y,1,1)                                                                 = date.civil(y,12,31)                                                                 holidays.between(from, to, :any ).each |date|                                             lname = date[:name]         ldate = date[:date]         lregion = date[:region]         holiday.create(name:  lname)                                                  #holiday created         holidate.create(date: ldate)                                                  #creates holidate         r_date.create(holidate_id: holidates.first.id, holiday_id: holidays.first.id) #this should create relation between holiday , it's date         region.each |x|              if false==true                                                            #this "atually" (it's false==true testing purpose) should test, if there country countrycode                country.create(countrycode: x , name: gets)                              #creates country             end             r_country.create(country_id: countries.first.id, holiday_id: holidays.first.id) #this should create relation, between countrycode , holiday         end     end     y=y+1 end 

but honest, have no idea how it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -