Take the 2-minute tour ×

I'm new to developing in Ruby and have mostly been using irb to experiment with code. For longer scripts, it would be helpful to be able to run them in my native browser (similar to how I run php scripts through MAMP). I believe there is a way to do this using localhost:3000 but I have not been able to get it to work. So my question is, what is the best way to view Ruby scripts in my native browser?

share|improve this question
Your question is a bit confusing. Are you talking about a standalone Ruby program or a Rails application? Do you want to execute the script or look at its source code? –  John Topley Apr 26 '09 at 16:24
I'm talking about a standalone Ruby program, which I'm now realizing may only be possible to run over Terminal, as it is Rails which supplies the html code that a browser would read.. Does that sound correct? –  jwb Apr 26 '09 at 16:39
Yes, although you can run Rails code through the Terminal too using script/console (think of it as an IRB that has access to your Rails models and controllers). –  John Topley Apr 26 '09 at 16:43
add comment

3 Answers

Well, running some Ruby code in IRB has nothing to do with using the Rails framework.

Follow a tutorial (for example this one) to learn the Rails framework itself now you have some understanding of the Ruby language.

Good luck.

share|improve this answer
add comment

I don't see how this would really be helpful to you, but it would be pretty easy to put your code into a simple Sinatra route and have that serve the result of the code into a browser if you want. Then you can just…

require 'rubygems'
require 'sinatra'
get '/' do
  "Hello World! This is file #{$0} live from Boulder!"

And when you access the server on your local computer, it will print whatever you put in the method.

I would be interested to hear why you want to do this rather than IRB, though. This seems like kind of a perverse way to code in most cases.

share|improve this answer
add comment

Rack is a Ruby webserver interface, you probably want to use that to hook your ruby script up with a server.

share|improve this answer
add comment

Your Answer


