I have some problem. I have many strings with keys and their belongings, keys are always the same. String looks like "key1=value1;key2=value2..." . So I made global Hash with arrays as values and want to store all data from strings into that hash so I made function:
<%
$all={}
for len in (0..$authors.length-1)
$all[$authors[len]] = Array.new #authors are defined and filled earlier
end
def add_hash(from)
the_from = from.to_s.split(";")
for one in the_from
splitted = one.split("=")
for j in (0..$authors.length.to_i-1)
if($authors[j] == splitted[0])
$all[$authors[j]] << splitted[1]
end
end
end
end
%>
but it doesn't seem to work, is something wrong in my code? (note: I can only use Ruby on Rails code)
add_hash, if you were expecting it to do something. Not sure what the point of the initial hash init is, you can set a default hash value in theHashconstructor. Not sure why this is in what appears to be an ERB template, either. - Dave Newton$authorsis made of. Also, be aware that variables are not named with $ sign in ruby. You can also usearray.each_with_index { |value, index| #your code }. - Wawa Loo