Book Image

Ruby on Rails Enterprise Application Development: Plan, Program, Extend

By : Elliot Smith, Rob Nichols
Book Image

Ruby on Rails Enterprise Application Development: Plan, Program, Extend

By: Elliot Smith, Rob Nichols

Overview of this book

<p><br />All businesses have processes that can be automated via computer applications, thereby reducing costs and simplifying everyday operations. This book demonstrates that a modern web application framework makes an ideal platform for such applications. It shows how the attributes that make the Rails framework so successful for Internet applications also provide great benefit within a business intranet. These attributes include easy roll-out and update of applications, centralized processing and data handling, simple maintenance, straightforward code development, and scalability.<br /><br />Ruby on Rails is an open-source web application framework ideally suited to building business applications, accelerating and simplifying the creation of database-driven websites. Often shortened to Rails or RoR, it provides a stack of tools to rapidly build web applications based on the Model-View-Controller design pattern.<br /><br />This book covers topics such as installing Ruby, Rubygems, and Rails on Windows, Linux, and Mac OS X; choosing and installing a database; installing an IDE for Rails development; setting up a Subversion repository to manage your code; creating a new Rails application; understanding Rails models; understanding controllers and views; improving user interfaces with Ajax; using Rails plugins to manage file uploads; using Capistrano to manage application deployment; techniques for scaling Rails applications, such as caching and using Apache to proxy through to the Mongrel server. The example application is straightforward to develop, easy to roll out, and simple to maintain.</p>
Table of Contents (16 chapters)
Ruby on Rails Enterprise Application Development
Credits
About the Authors
Preface
Index

Serving Installed Gems


To explain how this technique is applied, let's remind ourselves of Acme's setup. They have a production machine to which their applications are deployed, which contains most of the gems required by the developers (see, Chapter 3). Note that I said most, as Capistrano is not installed: technically, it is only required on the developer machines. However, to be able to serve it from the production machine, it needs to be installed on that machine too. (The gem_server command only offers up gems installed on the machine where it is running.) They install Capistrano (and its dependencies) with the following:

$ gem install capistrano -y

Next, they can make the gems on the production machine available via HTTP using this simple command:

$ gem_server
[2007-07-03 21:34:38] INFO  WEBrick 1.3.1
[2007-07-03 21:34:38] INFO  ruby 1.8.4 (2005-12-24) [i486-linux]
[2007-07-03 21:34:38] INFO  WEBrick::HTTPServer#start: pid=7543 port=8808

As you can see from the output, this starts a WEBrick server on the default port 8808 (gem_server -p N can be used to start the server on port N). Browsing to http://<server address>:8808/ (replacing <server address> with the IP address or domain name of the production machine) will now yield the documentation for the gems on the server. We had a brief look at this feature in the section: A Note on Rails Documentation in Chapter 3. If the gems were installed without documentation (using the --no-rdoc switch), you will just get a list of the installed gems without documentation links.

But there is another hidden aspect to the gem server: if you browse to the same address with the path /gems/, i.e. to http://<server address>:8808/gems/, you'll see the gems installed on the server displayed as links.

This indicates that the gem server is presenting its installed gems over HTTP. Once this is up and running, you can now use the gem command line tool on a developer machine to list the gems on the gem server:

$ gem list --remote --source http://192.168.13.131:8808
Bulk updating Gem source index for: http://192.168.13.131:8808

*** REMOTE GEMS ***

actionmailer (1.3.3)
    Service layer for easy email delivery and testing.
... etc. ...

(Replacing the IP address of the --source URL with the one for your server, of course.)

You can also install a gem from your own gem server with:

$ sudo gem install rails -y --source http://192.168.13.131:8808
Password:
Bulk updating Gem source index for: http://192.168.13.131:8808
Successfully installed rails-1.2.3

Setting Your Gem Server as the Default

If you want to configure gem to use your gem server as the default repository, create a file called .gemrc in your home directory (/home/username on Linux, Documents and Settings\Username on Windows). Next, add this single line (it's a YAML file):

gem: --source http://192.168.13.131:8808 -y

Remember to replace the --source URL with the one appropriate to your server. Note that I also added the -y switch to ensure that all dependencies are installed each time you install a gem. Now, each time you install a gem, your intranet gem server will be used as the default repository, rather than the public Internet gem repository.