I am following the Rails Tutorial by Michael Hart and I am already on Chapter 7. But I wanna do something different right now, which the tutorial doesn't teach. I wanna run a script file inside my webpage. How I can do that? I saw other posts here saying to use Sinatra, but since I am following this tutorial I don't think it is such a good idea to use it because it can make everything different from the tutorial.
Here is the simple script I wanna run on my webpage:
#Somando idades
def soma_vetor_excluindo(index,vet)
soma = 0
for i in 0..9
if(i!=index)
soma = soma + vet[i].to_i
end
end
return soma
end
def soma_vetor(vet)
soma = 0
for i in 0..9
soma = soma + vet[i].to_i
end
return soma
end
def maior_vetor(vet)
maior = 0
for i in 0..9
if(maior < vet[i])
maior = vet[i]
end
end
return maior
end
idades = (0..9).collect{rand(99)+1}
soma_idades = (0..9).collect{0} soma = 0
print "#{idades} \n"
for i in 0..9
soma_idades[i] = soma_vetor_excluindo(i,idades)
end
print "#{soma_idades} \n"
div = soma_vetor(soma_idades) / 9
resp = div - maior_vetor(soma_idades)
puts "#{resp}"