First time with Ruby - how to print "Hello World!" via web-server

Hello Everyone,

first off - I'm NOT a programmer. I know HTML/CSS very well and PHP
quite well, yet not I'm in need of a more "active" language and I've
decided to go with Ruby.

Thing is, I've been able to find ton of tutorials, but NOT ONE answers
the most basic question - what exactly do I have to upload to the server
to simply get a (any) response from Ruby (through a browser, using a
regular shared webhosting).

The closest "answer" I could find was that unlike HTML/PHP, Ruby needs a
specific file structure (controllers, models, views) but still - neither
of the 30+ tutorials I've browsed through tells me:
- How many files exactly do I require for a simple "Hello World!"?
- What extensions should these files have?
- Where to put which files?
- What the hell should these files contain?

Now, I can "play" with Ruby via the command line locally and I can just
create an .rb file and run it from there, but that's not the point, I
want it to show online via a browser and as ridiculous as it sounds - I
don't know how to do that?

Add. infos:
- I'm trying to run it on a cheap shared web-hosting (Linux server).
- Ruby on Rails + gems are installed there, can access them via the
cPanel.
- I've created a test-app through the cPanel - with success.
- I've created a rewrite
- I can access the subdomain via my browser and I'll see the "Welcome
aboard" start page.

What now?

I just can't continue to learn the language via simple out-of-context
examples via the command line while I have no idea where to upload which
files to make it really function on-line :frowning:

Please help.

Have you looked at http://ruby.railstutorial.org/ ?
In particular, check out "Lesson 1: From zero to deploy"

After working through that, you will probably be able to get started
in your environment.

Dan Nachbar

Hello Everyone,

first off - I’m NOT a programmer. I know HTML/CSS very well and PHP

quite well, yet not I’m in need of a more “active” language and I’ve

decided to go with Ruby.

Thing is, I’ve been able to find ton of tutorials, but NOT ONE answers

the most basic question - what exactly do I have to upload to the server

to simply get a (any) response from Ruby (through a browser, using a

regular shared webhosting).

The closest “answer” I could find was that unlike HTML/PHP, Ruby needs a

specific file structure (controllers, models, views) but still - neither

of the 30+ tutorials I’ve browsed through tells me:

  • How many files exactly do I require for a simple “Hello World!”?

You should google for tutorials on installing ruby and rails on your computer and then how to create a rails project via the console using the ‘rails new’ command. This command creates an app structure and then probably such a tutorial will show you how to render a page, or better, show you how to create a simple CRUD model.

So your steps are:

  1. Install ruby and rails locally

  2. Genearate a project: ‘rails new myproject’

  3. Create some content

  4. Deploy somewhere. I recommend you use Heroku as it will be the simplest way for you to get something on the web.

Hi,

This is the best tutorial that i saw about Rails…

http://ruby.railstutorial.org/chapters/static-pages#top

I think that you’ll find the answers there.

Note. Sorry about my english, this is not my primary language.

http://www.sinatrarb.com/ -> If you’re looking for a Hello World application with Ruby (independent from Rails)

Add. infos:
- I'm trying to run it on a cheap shared web-hosting (Linux server).

That's probably your problem -- most cheap shared web hosting services aren't running a deployment stack for Rails.

- Ruby on Rails + gems are installed there, can access them via the
cPanel.
- I've created a test-app through the cPanel - with success.
- I've created a rewrite
- I can access the subdomain via my browser and I'll see the "Welcome
aboard" start page.

OK, maybe I'm wrong, perhaps your "cheap" shared web host does have a Rails deployment stack.

Four tips for you to point you in the right direction:

1) try deleting the file public/index.html. That will make the "Welcome aboard" message go away. In its place you will get a nice "Route could not be found" error, so go check out your routes.rb file and let about how the Rails router works.

2) You can do all of this locally, you don't need a web host, try starting Webrick ("rails server" in rails 3 or "script/server" in rails 2) and point your browser http://localhost:3000

3) Check out Phusion Passenger

4) When you're actually ready to deploy an app for real, don't mess around with your "cheap shared web-hosting" provider -- go to Heroku. It's cheap, as-in basically free, for small low-traffic apps.

-Jason

...

The closest "answer" I could find was that unlike HTML/PHP, Ruby needs a
specific file structure (controllers, models, views) ...

By the way, this is incorrect.
You are confusing Ruby (the language) and Rails (the web framework).

Ruby can be run as a stand-alone program directly via CGI or as code
embedded
within HTML (e.g. via erb). In contrast, Rails does have a specific
file structure, etc.

And, as mentioned in another reply, there are other Ruby-based web
frameworks (e.g. Sinatra) that are worth looking into.

Dan Nachbar

-- -- wrote in post #1024089:

Hello Everyone,

first off - I'm NOT a programmer. I know HTML/CSS very well and PHP
quite well, yet not I'm in need of a more "active" language and I've
decided to go with Ruby.

How can you not be a programmer and know PHP quite well? That's a
contradiction. PHP is a programming language. If you know it then YES
you are a programmer.

Thing is, I've been able to find ton of tutorials, but NOT ONE answers
the most basic question - what exactly do I have to upload to the server
to simply get a (any) response from Ruby (through a browser, using a
regular shared webhosting).

Answer, you technically don't have to upload anything to any server to
get a Rails application to respond to a request through a web browser.

Try this once you have Rails properly installed. (Doesn't actually have
to be Rails, you could do the same thing with Sinatra, or whatever Ruby
based web framework you choose, but I'll show Rails here):

gem install rails
....
....
rails new my_app
cd my_app
rails g[enerate] controller greetings index
....
....
vim app/views/greetings/index.html.erb
Delete all lines and add the following to the file

I think what the OP means is that he's not a *seasoned* programmer,
with the kind of multi-language experience that makes it much easier
to pick up another one.

-Dave

Thanks, everyone. Seems I've missed "ruby.railstutorial.com", thanks for
the tip, I'll check it out.

As for "cheap host" - it's Hostnine.com. I'm referring to it as cheap
because it's just $7/month for a shared hosting plan, it's not THAT bad.
Of course I would not use this plan to run a popular high-traffic site,
but then - IF I'd have one, then I'd start thinking about dedicated
hosting (or rather - I'd think about it once I'd realize it's starting
to get big).

Anyway, it's good for my current needs. Still, thanks for the tip on
Heroku. For now, I'd rather stay away from hosts offering completely
free service :wink:

Next - yes, I'm probably confusing Ruby itself with the framework,
thanks for clarifying.

How can I not be a programmer and know PHP? It depends on the definition
of "being a programmer". IMO, a programmer is someone who:
1. Knows many programming languages and often uses them because... he's
programming... a lot (probably for a living) :wink:
2. Would never ask the questions I asked :wink:

I, on the other hand, happen to have an idea once in a while (if fact,
lots of them, all the time, but once in a while there's one that stick
around "forcing" me to execute it) and the programming language is just
a tool I need in order to make it work. It's like driving a car (me) and
being a car mechanic (a programmer). Although the driver CAN learn about
the car's basic mechanics and could fix some basic issues, he won't be
able to build a car just due to the lack of knowledge (and/or interest).

When HTML wasn't functional enough I needed some (a bit) PHP. I could
actually make my idea work just with pure PHP, but it would result in
the most user-UNfriendly experience ever and kind of... miss the whole
point which is supposed to be an EASY way to... achieve something (can't
give you the details, sorry). So now I need something to make a website
which will allow the user to:
- return the results "live" without reloading the whole page and
communicate with the MySQL database in the process,
- drag and drop things, snap them to some positions... and again,
communicate with the db in the process.

Would PHP allow me to do that (with a PHP framework)? PHP has a
framework? Is framework the part that allows a webpage to be dynamic? Or
maybe I should use Perl/Python/Java I don't really care. I've found lots
of opinion that Ruby could do that and it's apparently quite easy/easier
than using other languages.

Now, would you still consider me a programmer? I wouldn't :wink:

OK then, off to the tutorial. Thanks again so far, let's see where it
gets me :slight_smile:

I watched the "Lesson 1: From zero to deploy" video from
ruby.railstutorial.org and... where exactly does he say how to make just
one simple "Hello world" line appear?

I've learned things about git, Github and Heroku, but if you ask me
where can I upload my simple one-liner manually via FTP to make it run -
I still can't tell you :frowning:

I can put a PHP file with <?php Print "Hello World!"; ?> in it to the
public_html folder - works. Where to put which file to make it work with
Ruby - still no clue.

Still, knowing where the "Welcome aboard" page is, I'll take a look at
ERB and if I can put anything Ruby-ish <% here %>, it'll already be a
success... until we get to the part where I'd want Ruby to communicate
with a database.

The first tutorial lesson is basically a presentation of getting the
environment and tools working, introduction to git and heroku and doing a
rails deployment. He doesn't do anything with hello world or attempt to
hook anything else up in that section (at least not in the pdf and I don't
remember anything in the video)....

In the second section he starts doing some trivial db stuff and continues
the deployment to heroku and revision control on github. But no real hookup
yet other than manually navigating to the pages...

In the next section he starts putting more of it together, some static html,
some TDD, some actions and other fun things... I'm just finishing that part
of it now and moving to the next..

Hope this helps.... good luck!

Max

Perhaps this is more what you have in mind -

# the following assumes some sort of *nix shell on your
# local machine and Rails 3.1

rails new helloapp
cd helloapp
rails generate controller Pages hello
echo '<%= "Hello World!" %>' >> app/views/pages/hello.html.erb
# ftp the helloapp directory tree to your server
# prod your server as necessary so that it recognizes
# the newly uploaded files
# point your browser at your_server/pages/hello
# bask in the glory that is Hello World!

PS - I happen to be in the process of preparing a
"getting to 'hello world' " screencast that shows this process
for Rails via Passenger on a shared Debian configuration as
provided by Dreamhost (Yet another discount hosting
company that I happen to use and know well. I have no affiliation
with Dreamhost other than being a happy customer.) If you
(or anybody else interested for that matter) want to contact
me off list, I'll be happy to let you know when it is ready for
beta viewing.

Dan Nachbar
dan@nachbar.com

-- -- wrote in post #1024115:

How can I not be a programmer and know PHP? It depends on the definition
of "being a programmer". IMO, a programmer is someone who:
1. Knows many programming languages and often uses them because... he's
programming... a lot (probably for a living) :wink:
2. Would never ask the questions I asked :wink:

I hope you realize I was mostly kidding about that. I know what you
meant, it just seemed funny to me that you first said "I'm not a
programmer" then said "I know PHP quite well" -- paraphrased.

Now, would you still consider me a programmer? I wouldn't :wink:

I consider a person to be a programmer once they write their first
program. Even if that happens to be: puts "Hello World". Everything
beyond that is the person's level of experience as a programmer.

You have shown interest in programming, and you have written at least
some PHP code. Congrats, you are a programmer. I don't see that there is
some "magical" level of experience where suddenly a person transforms
into a programmer. I've been programming for a really long time and I
still learn something new on a nearly daily basis.

-- from a separate followup post by the OP

I can put a PHP file with <?php Print "Hello World!"; ?> in it to the
public_html folder - works. Where to put which file to make it work with
Ruby - still no clue.

Okay, here is a REALLY important point you're not taking into
consideration. The reason that snippet of PHP works, in what appears to
be some magical transparent way, is that there is a complex and
sophisticated module, written in C, that was included into the web
server (Apache, IIS, or whatever) by your shared hosting provider. This
"special" module knows how to interpret the <?php> tags and transform
them into plain old HTML before delivering the response to the client
web browser.

Rails by contrast takes a different approach. In a Rails application
there may be a small module (in the case of something like Phusion
Passenger) or simply some web server configuration that is responsible
for directing requests to the application from the web server.

The point I'm making here is that the vast majority of the work that
would be performed by the PHP web server module is actually deferred to
the Rails application itself. Hence the Rails routing system that
directs requests to the proper Rails controller classes, which in turn
are responsible for rending eRB templates into HTML and delivering the
response to the client browser.

You're trying to directly compare two completely different approaches to
web applications where such a direct comparison simply isn't possible.