RubyOnRails

From SME Server
Revision as of 00:54, 29 October 2009 by Thf (talk | contribs) (→‎Install RubyGems)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Ruby on Rails 2.0 on the SME Server 7

Web development that doesn't hurt

Ruby on Rails is an open-source web framework that's optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favouring over configuration.

Here is how to get up and running with Rails on your SME Server.

You need to be root (su -) to do the following installation actions.

Add CentOS – testing Repository

The base CentOS repositories have an outdated Ruby version, so we need to get it from the CentOS testing repository.

Setup the centos-testing repository as per below:

db yum_repositories set centos-testing repository \
BaseURL http://dev.centos.org/centos/4/testing/i386/ \
Name 'CentOS - testing' \
Visible yes \
GPGKey http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing \
GPGCheck yes \
status disabled

Regenerate the yum.conf file:

signal-event yum-modify

Install Ruby

Then use yum to install ruby and associated packages:

  yum --enablerepo=centos-testing install ruby ruby-libs ruby-devel \
      ruby-mysql ruby-ri ruby-postgres ruby-rdoc ruby-docs

Check that ruby is properly installed with:

  # ruby -v
  ruby 1.8.5 (2006-08-25) [i386-linux]

Install RubyGems

RubyGemsis the ruby packaging system. wget the latest version from the RubyForge repository. Unpack the tar file and install the package as per below:

  wget -c http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
  tar xzvf rubygems-1.3.5.tgz
  cd rubygems-1.3.5
  ruby setup.rb
  cd ..

Install Rails

With the gem package manager installed, you are now one step away from installing Rails

  gem install rails

At the moment (Jun 2009) this will install Rails 2.3.2 onto your system, ready for deploying Rails based applications (or creating your own).

Creating a New Rails Application

To create a Rails application, open a shell and navigate to a place in your file system where you want to create your application.

 > mkdir work
 > cd work
 work> rails demo
     create
     create  app/controllers
     create  app/helpers
     create  app/models
        :     :    :
     create  log/development.log
     create  log/test.log

Change to the directory in which your application was created:

 work> cd demo
 demo> ls -p
 app/      config/  db/      doc/   lib/  log/    public/  
 Rakefile  README   script/  test/  tmp/  vendor/

Start the embedded webserver:

 demo> ruby script/server
 => Booting WEBrick
 => Rails 2.3.2 application starting on http://0.0.0.0:3000
 => Call with -d to detach
 => Ctrl-C to shutdown server
 [2009-06-30 10:12:48] INFO  WEBrick 1.3.1
 [2009-06-30 10:12:48] INFO  ruby 1.8.5 (2006-08-25) [i386-linux]
 [2009-06-30 10:12:48] INFO  WEBrick::HTTPServer#start: pid=3424 port=3000

And open up your browser to http://your_server_url:3000 and admire the welcome page of your new Rails application!

References

RubyOnRails http://rubyonrails.org/

RubyGems package manager http://rubygems.org/

Extending Rails with plugins http://wiki.rubyonrails.org/rails/pages/Plugins

Recommended Editors

TextMate http://macromates.com/ (MAC OS X)

RadRails http://www.aptana.com/rails/ (Aptana Studio -or- Eclipse IDE)