0

I'm new to rails and I'm working on this project: I have done a ruby script which needs an input and that prints some outputs. Basically it takes the first n decimal digits of PI and then it calculates some stats. I need to use a rails web app to insert the input, which is a number, and to print the decimal digits and 10 stats rows.


This is the ruby script

require 'bigdecimal/math'
#PI decimals generator
i = 0
j = 0
a_pi = Array.new
print "Insert how many digits do you want to calculate: "
dig_n = gets.chomp.to_i
x = BigMath.PI(dig_n)
a_pi = x.to_s.split('')

begin
  a_pi.shift
  i += 1
end until i == 3

arr_length = a_pi.length

begin
  a_pi.pop
  j += 1
end until j == arr_length - dig_n

pi_dec = a_pi.join.to_i
puts pi_dec

I'm using Ruby 2.6 and Rails 6

1 Answer 1

0

I think you are thinking about this the wrong way around. What you want is more "a web app/web form that does something with input". Rails might be too much for your use case. If you are not bound to Rails you might want to look into other / lighter web frameworks in ruby like Sinatra or Hanami. This could help: Run ruby script from a HTML form

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.