GIT with branches
October 31, 2008
Ruby Gems
February 4, 2007
Using Ruby Gems
You may want to add functionality to your application using Ruby Gems. A gem is a packaged Ruby application or library. A great introduction to Ruby Gems can be found here. Basically, Ruby Gems keep you from having to reinvent the wheel, by providing you with modular pieces of code that can be accessed from within your application’s code.
By default, some gems will come pre-installed with your hosting plan. Generally these are Rails-relevant gems (ActiveRecord, ActionMailer, etc.). To see a list of installed gems at any time, type “gem list –local” from an SSH window.
To install new gems, issue the command “gem install <gem-name>” (where <gem-name> is the name of the gem you wish to install). This command will first search your local machine for the specified gem, and if not found, will attempt to automatically download the gem from RubyForge, an online gem repository. Check RubyForge for a complete listing of available gems or check the link here for a more condensed listing. More installation options can be found by typing “gem install –help”.
By default, gems will be installed to ‘/usr/lib/ruby/gems/1.8/gems/’.
Freezing Ruby Gems
Whenever a new gem version appears on the host, your Rails application will attempt to automatically upgrade to that version. This is convenient when in development, but after moving to production, it can cause things to break unexpectedly. For obvious reasons, you don’t necessarily want your application being updated after it has been published. To prevent gems from updating, change directories to your application root, and issue the command “rake freeze_gems”. This copies the gems from /usr/lib/ruby/gems/1.8/gems/ (the default location) to <your-app-name>/vendor/ and keeps them from being automatically updated.There is one caveat with the “rake freeze_gems” command. It will only freeze gems that are Rails-relevant. If running this command doesn’t freeze the gem(s) you want it to, (i.e. they are not found in <app-name>/vendor/) you will need to use the solution found here.
This section is intended only to give a brief introduction to concept of freezing gems. If this is something you are interested in doing, it is highly recommended that you read up on the documentation at http://www.rubygems.org for more information.
Mongrel_server
January 5, 2007
Getting Started
The easiest way to get started with Mongrel is to install it via RubyGems and then run a Ruby on Rails application. You can do this easily:
gem install win32-service (pick the most recent one)
gem install mongrel (pick the win32 pre-built)
Win32 Support
Win32 is fully supported by Mongrel with services and CPU affinity support.
The main thing with Win32 support is that there is no fork API for Ruby, so you have to use the services features to get persistent servers running. You can get this services support by doing:
gem install mongrel_service
And then just run mongrel_rails to see what services:: commands are available.
Running The Service
After you do the gem install, find a Rails application you want to run and do:
$ mongrel_rails service::install -N myapp \\
-c c:mypathtomyapp -p 4000 -e production
$ mongrel_rails service::start -N myapp
Now hit the port and poof, works (or should).
The application will stop if you use:
$ mongrel_rails service::stop -N myapp
NOTE: Stop reports an exception but does stop the service.
Now the really great thing is that you can just do all this from the Services control panel like your Rails application is a regular Windows service.
Even works in development mode, which is pretty nice.
Making you Service autostart with Windows
By default, the new Mongrel service get installed to be run manually, using Mongrel’s commands or the Service Manager. You could tweak it to start automatically when Windows start, just use the Service Control commandline tool:
$ sc config myapp start=auto
Also, you can configure the services that are neede to make it work, like database support:
$ sc config myapp start=auto dependency=MySql
CPU Affinity
Mongrel’s win32 support actually is able to set the CPU affinity of a running Mongrel service. This is pretty neat since it means if you’re running a fancy SMP machine or a dual core that pretends to be SMP, then you can force Mongrel onto one of them and get a nice little boost.
It’s pretty easy to use, just pass the -u or—cpu option to the install command and give a CPU of 1-X. That means if you have 4 CPUs and you want Mongrel on #4 then do:
$ mongrel_rails service::install -N myapp
-c c:mypathtomyapp -p 4000 -e production -u 4
Pretty much the same command, just one more option and you’re done.
Welcome
December 13, 2006
Welcome to learn Ruby,
Now you can download ‘Radrails (version 0.7.2)’ editor for developing Ruby On Rails application for Windows, Mac OSX and Linux at