A few weeks ago i decided that i wanted to learn ruby.
So i started googleing for tutorials, and other nice to know stuff.
Ive read some stuff, and now i want to get started making webpages.
Heres where i run into problems.
All the documentation, faqs and tutorials assume you know how to make
ruby
work.
For php, i would download xampp put my scripts in the htdocs folder,
start
the server and then view everything in the browser by typing the url.
How the hell do i do the same with ruby? Theres lots of tutorials
explaining how to download railsinstaller - but none of them exlains how
i view the code in a browser... At least none that ive been able to
find.
If you already got XAMPP installed, you can run the Ruby scripts as CGI
scripts. Simply put the files into the "cgi-bin" directory, give them a
".cgi" ending and output the HTTP headers. Something like this:
However, this is a very inefficient way to run scripts, since the Ruby
interpreter and the script have to be started for every request. So you
should use this only for testing or small sites. For bigger sites you
need more advanced techniques like FastCGI, SCGI or whatever is
currently en vogue. You'll need to do some reading for that.
? If you're creating a web app in any language, you'll do the exact
same thing: start the server and view the results in a browser. You
mention "railsinstaller". Do you have Rails installed? If so, starting
it is as simple as typing `rails s` in your app directory.
···
On Mon, Jul 23, 2012 at 2:23 AM, Morten T. <lists@ruby-forum.com> wrote:
How the hell do i do the same with ruby? Theres lots of tutorials
explaining how to download railsinstaller - but none of them exlains how
i view the code in a browser...
"railsinstaller" was a typo - ive been reading "ruby on rails" all week
long on the search results. I meant "Rubyinstaller"
I was told that ruby is a language you can use to make dynamic webpages
like you can with PHP and ASP.NET.
This is what i wish to learn - so i need a local server so i can play
around with the language. Later on, when i feel confident with ruby -
ill try the rails framework.
About the steep learning curve - thats allright. Ive got a mindless job,
so i like the mental exersice it is to code...
I think there's been conflation of writing web pages in ruby with writing web pages using ruby on rails.
···
On Jul 23, 2012, at 8:09 AM, Hassan Schroeder <hassan.schroeder@gmail.com> wrote:
On Mon, Jul 23, 2012 at 2:23 AM, Morten T. <lists@ruby-forum.com> wrote:
How the hell do i do the same with ruby? Theres lots of tutorials
explaining how to download railsinstaller - but none of them exlains how
i view the code in a browser...
? If you're creating a web app in any language, you'll do the exact
same thing: start the server and view the results in a browser. You
mention "railsinstaller". Do you have Rails installed? If so, starting
it is as simple as typing `rails s` in your app
I was told that ruby is a language you can use to make dynamic webpages
like you can with PHP and ASP.NET.
Yes, but unlike PHP or ASP.NET, Ruby is an all-purpose language. It's
not just for webpages.
This is what i wish to learn - so i need a local server so i can play
around with the language. Later on, when i feel confident with ruby -
ill try the rails framework.
Ruby is not a compiled language, it is always interpreted. Running your script from the command prompt is the way you run your program.
If you want to make web pages, the go-to solution in the ruby community is typically ruby on rails. It's not hard to get up and running with it quickly, but it is a very large framework. As big as something like cakephp. The ruby on rails website links to tutorials.
You don't need much ruby knowledge to start with ruby on rails, but the more you have the more the syntax used inside ruby on rails will make sense.
Jam
···
On Jul 24, 2012, at 1:31 AM, "Morten T." <lists@ruby-forum.com> wrote:
Hi Again...
I just made it work somewhat...
I can now run a script from the command promt...
Id still like to be able to use ruby to make webpages, or compile it to
a program or something...
Id still like to be able to use ruby to make webpages, or compile it to
a program or something...
Try Sinatra. If you have Ruby installed, you should have the `gem` utility
installed. Use that to install Sinatra from the command line like this:
$ gem install sinatra
(where the ca$h indicates the prompt)
Then make a text file named hello_world.rb and put this code in it:
require 'sinatra'
get('/') { 'hello, world' }
Sinatra is smart and will set up its own server if you don't deal with all
that stuff for it. So back to the command line, to run the program:
$ ruby hello_world.rb
And it will say something like this:
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup
from Thin
Thin web server (v1.3.1 codename Triple Espresso)
Maximum connections set to 1024
Listening on 0.0.0.0:4567, CTRL+C to stop
Which means for me that it's chosen the Thin web server (you'll probably
get webrick), and it's on port 4567, so in the browser go to "0.0.0.0:4567"
and you should see "hello world". There, you have now served up a web page
with Ruby. The string 'hello world' inside the brackets is the page you're
returning. If you were to return a different string, e.g. one that you
constructed, or one that was the result of a rendered template (which would
feel a bit more like php), then you could dynamically create any page you
liked. For more on Sinatra, check out http://www.sinatrarb.com/
···
On Tue, Jul 24, 2012 at 2:31 AM, Morten T. <lists@ruby-forum.com> wrote:
I was told that ruby is a language you can use to make dynamic webpages
like you can with PHP and ASP.NET.
Yes, but unlike PHP or ASP.NET, Ruby is an all-purpose language. It's
not just for webpages.
Oh, really?
Even better
What would i need to compile ruby code into a program? Maybe thats what
i should ttu instead...
This is what i wish to learn - so i need a local server so i can play
around with the language. Later on, when i feel confident with ruby -
ill try the rails framework.
Have you managed to get the CGI scripts running?
I have not tried yet - i wanted to get a few answers so i could try out
a few things at the same time. To see what i prefer...
What would i need to compile ruby code into a program? Maybe thats what
i should ttu instead...
You don't compile Ruby programs. You simply save the source code in a
file, pass it to the Ruby interpreter, and then the script runs.
Just like with most other scripting languages.
Morten T. wrote in post #1069938:
Id still like to be able to use ruby to make webpages
Isn't that just what I've explained earlier?
However, since you've never written a Ruby program before, it may be a
bit too early to start making webpages. I'd actually start off with a
good Ruby book (I liked "The Ruby Programming Language"), then read into
the basics of web programming (how do web servers work, how does HTTP
work) and *then* start with the webpages.
Ruby isn't PHP, where you can simply throw some code in a HTML page and
do "trial and error" until you get the desired output. That won't work
with Ruby.