Rails Quick Tip #1 : Simplifying webrick command

March 4, 2011 | In: ror, ruby

If you want to learn RoR, you need to set it up on your machine so you can dive in directly into the codes so you can see how it really works.

Let’s install our first sample RoR app.

$ rails test_app

This will generate the rails default set of files.

Now let’s run the server

$ ruby script/server

You will something like :

=> Booting WEBrick...
=> Rails 2.2.3 application started on http://127.0.0.1:3000
=> Ctrl-C to shutdown server; call with --help for options
[2011-03-04 11:38:44] INFO  WEBrick 1.3.1
[2011-03-04 11:38:44] INFO  ruby 1.8.7 (2010-01-10) [i486-linux]
[2011-03-04 11:38:44] INFO  WEBrick::HTTPServer#start: pid=5246 port=3000

Now open your browser at http://localhost:3000 and you will something like :
Welcome aboard
You’re riding Ruby on Rails!

Before we go even further, let’s go back to the our first tip:
– copy the generated ‘test_app/script’ (script only not the other files inside test_app) into the location where you have set it as ENVIRONMENT variables, in my machine ‘/usr/local/bin’

$ cp -R test_app/script /usr/local/bin

Make sure you have the right permission on the destination folder, if not:

$ sudo cp -R test_app/script /usr/local/bin

You will be prompted for the password.

To see if it works, try to stop webrick and run it again using :

$ script/server
=> Booting WEBrick...
=> Rails 2.2.3 application started on http://127.0.0.1:3000
=> Ctrl-C to shutdown server; call with --help for options
[2011-03-04 11:38:44] INFO  WEBrick 1.3.1
[2011-03-04 11:38:44] INFO  ruby 1.8.7 (2010-01-10) [i486-linux]
[2011-03-04 11:38:44] INFO  WEBrick::HTTPServer#start: pid=5246 port=3000

You will notice that you don’t have to put ‘ruby’ at the front.

HTH

Comment Form