Ruby On Rails

From Helpme

Jump to: navigation, search

Contents

Availability

Ruby on Rails is available on the Linux workstations in the Design Center.

  • Ruby Version: 1.9.x
  • Rails Version: 3.2.x

Setting up your environment

To put Ruby and Rails into your environment, type:

$ setup ruby

Now you should be able to run commands like:

$ ruby --version
ruby 1.9.3p385 (2013-02-06) [x86_64-linux]
$ rails --version
Rails 3.2.12

Creating a new Rails app

To create a new rails application, simply run:

$ rails new ~/rails/app_name

This will create the directory "~/rails/app_name" that contains your rails application, along with several default files and directories underneath it that you can modify to further build your application.

Running your Rails app

$ hostname
linux60805
$ cd ~/rails/app_name
$ rails server -p $(rails-port.pl)
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3002
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-02-19 11:38:10] INFO  WEBrick 1.3.1
[2013-02-19 11:38:10] INFO  ruby 1.9.3 (2013-02-06) [x86_64-linux]
[2013-02-19 11:38:10] INFO  WEBrick::HTTPServer#start: pid=6507 port=3002

Note the call to "rails-port.pl" above. This is critical. If you do not do this, rails will attempt to start your application on the default port of 3000. If someone else on the system is already running their application, you will be unable to start yours unless you specify a free port. The "rails-port.pl" script finds a free port automatically, but only if you call it as described above.

Viewing your Rails app

To view your Rails application in a browser, you would then point your browser to:

http://<hostname>.dc.engr.scu.edu:<port>/

From the example above, we have started our rails app on host linux60805 port 3002, which means we'd go to:

http://linux60805.dc.engr.scu.edu:3002/

Further Reading

To actually do something useful with Rails, see your class handouts and/or visit:

Personal tools