Hi --

On Tue, 25 Mar 2008, Joan Gu wrote:

> I need to insert Broad Category value and Topics value into a table,
> doing something like this (where 'Police, Crime, Drugs' are topics
> values and 'Crime & Law Enforcement' is broad category value):
>
> obj1 = 'Police, Crime, Drugs'
> obj1 = obj1.split(',').map do |tag_name|
>  execute "insert into tags (name,counter) values
> ('#{tag_name.strip.downcase}', 0)"
>  t = Tag.find_by_name(tag_name.strip.downcase)
>  tt = t.tag_with('Crime & Law Enforcement')
> end
>
> When it comes with multiple broad categories and topics, I want to build
> an array in a form like
> [['Police, Crime, Drugs','Crime & Law Enforcement'],['Fire, Emergency
> Services','Emergency Management'], ['Schools, Colleges,
> Libraries','Education'],...]
> to iterate the executions. I worked for quite some hours, but still
> can't make it work. Can someone help?

I think you want something like this:

tagsets = [['Police, Crime, Drugs','Crime & Law Enforcement'],
['Fire, Emergency Services','Emergency Management'],
['Schools, Colleges, Libraries','Education']]

tagsets.each do |tagset|
   broad, topic = tagset
   broads = broad.split(",").map {|s| s.strip }
   puts "Broad: #{broads.join("; ")}\n\tTopic: #{topic}"  # etc.
end


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS   April 14-17          New York City
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
See http://www.rubypal.com for details and updates!