Ruby as a scripting language for a web server

Can Ruby be used as a scripting language with an HTTP server? I would like to be able to simply put some Ruby files in a web directory and be able to execute them from my browser - just like I did with PHP.

I have absolutely nothing against frameworks like RoR, but they told me that I should first learn Ruby and only then move on to higher levels. Of course, I could write some Ruby scripts and run them in the console, but I would rather get in / out from my browser :)

Is this even possible? Otherwise, how difficult would it be to build a fast and simple web infrastructure?

+3
source share
4 answers

, CGI Programming, Ruby.

, - - "Hello World" .rb .cgi chmod , "":

chmod 755 YourScript.rb

CGI , shebang . Ruby , , - ...

#!/usre/bin/ruby

(no promises )

CGI script. CGI script HTTP-: ( Ruby-, )

puts "Content-Type:text/plain\n"
puts "Content-Length:12\n"
puts "\n"
puts "Hello World!"

, PHP Perl script, , . ; .

+3

Sinatra - CGI/PHP, - , , Ruby , -.

+6

ERB PHP ( , ).

apache rhtml erb, OSX.

+5

, CGI.

- , , CGI.

( C/++ -, ).

+1

Source: https://habr.com/ru/post/1743401/


All Articles