Recent Blog Posts
Blogs » Ruby on Rails
Get on Track
: Ruby on Rails BlogSmooth your deployment with Passenger
I alluded to the release of Phusion’s Passenger (AKA mod_rails) - an Apache module that can run multiple Rails sites, just as PHP does. The significance of this is pretty huge. Up until now, running rails has required running Mongrel behind an Apache proxy or using FastCGI (or preferably fcgid).
Although Mongrel did a sterling job, I have never been a big fan of having two points of failure - problems with either Apache or Mongrel would render your site unreachable. Not only that, adding capacity to your system required adding a number of mongrel instances, each with it’s own port and each with it’s own memory overhead, which can get very messy for shared hosting providers.
Passenger will allow hosting providers to install one Apache module, requiring the client to simply upload their application - no permission issues, or troublesome configurations files. However, it is also very useful for a developer - instead of having to run script/server when testing your application, you can install a local version of Apache, setup a few virtual hosts, and have instant access to your test sites.
Currently, Passenger only runs on *NIX type environments, eg Linux and OSX. The Phusion team have worked pretty …
Ruby On Rails Linkage: GitHub, Passenger and more…
The Rails core team is inching towards version 2.1 of Rails which adds a myriad of new features including named scopes, gem dependencies and native timezone support. The official launch of GitHub has seen an explosion of articles on how to use Git, and it looks like Rails can finally become a first class citizen on shared hosts. Here are some links where you can find out more:
- Geoff Buesing goes through the new Timezone support
- Ryan Daigle explains the new named_scope functionality and how Gem dependencies work
- Peter Cooper runs through some more resources for working with Git
- Phusion releases Passenger (AKA mod_rails), that allows Rails applications to be deployed via an Apache module, in a similar manner to PHP.
More on Passenger later.
Subversion gits the last train
There has just been an announcement that the Rails-core source code version control repository is moving over from Subversion (SVN) to git and they will be using Lighthouse for bug tracking instead of trac. Does this affect you? Not directly (unless you like playing on edge-rails), but it is a good excuse to talk about source code repositories and some of the differences between subversion and git.
What’s source-code version control?
Source-code repositories provide you with a central place to store your code — they will generally do this whilst maintaining a history of your “commits” (The action of saving code back to a repository). This means that you are able to roll back code any change that you have made. If you have ever been over-zealous with the rm -rf command, you may understand why this might be handy.
Another cool feature is the ability to branch (or take a copy of) your code - this allows you to keep, say, a development and a stable version. If you find a bug that needs patching in your production version, you can merge the change back in to the development branch thus avoiding regressions bugs.
There are a number of version control systems out …
Other cool ruby projects
With all the noise that Rails makes, you would be forgiven for thinking that it is the be all and end all of the Ruby world - sure it has popularised the language, but there are lots of other cool projects using the Ruby. Here are a few:
Merb
Merb is another full-stack web framwork, which works a lot like Rails. However, the author has stripped quite a bit of the fat away, and made the framework mush less opinionated as well as making it thread-safe. Rather than having a large monolithic core, Merb tries to be as modular as possible relying on third party gems for much of it’s functionality.
It includes support for different Object-Relational mappers (ORMs - the thing that mediates transactions between your application and your database), including DataMapper, Sequel and even the Rails default ORM: ActiveRecord.
Merb stands for Mongrel + ERB, so it isn’t suprising that they make up a significant part of the framework, although you can use HAML and SASS as your templating engine.
Camping
Camping is a micro-framework (only 4k!) designed by the disturbingly talented Why the Lucky Stiff. It is probably more an exercise is seeing how much you can do with little code, but …
alt.ruby
There is no denying that Ruby on Rails is creating some noise amongst the web development circles - you have read the blogs, and maybe bought the t-shirt, but did you know that Ruby as a language has been getting some attention too?
Up until now you would have been using the original Matz Ruby Interpreter (MRI) built by the Ruby designer - Yukihiro Matz Matsumoto. This is the standard interpreter that is installed on Linux and OSX by default. However, there have been a few issues.
- Speed: By design, an interpreted language is going to be slower than a compiled one - the interpreter needs to parse and compile the source on every run.
- Integration: If you want to connect to, say an ActiveDirectory server or MSQL server, you need libraries written in Ruby. This can cause some headaches if you try to use Ruby on enterprise
So a few groups of very smart people have been working towards different versions of the Ruby interpreter to alleviate this issues.
JRuby
JRuby is a port of the Ruby interpreter in Java. This is is probably the most mature, with a mostly complete library set, and can it run Rails (unofficially). As well as being able …
RESTful Rails. Part II
For those of you who have been waiting with baited breath to read the second installment of my RESTful Rails blog post, wait no longer! Although it started as a blog post, it ended up being expanded to a full blown article entitled Rapid RESTful Rails App — No Really!.
In the article you will learn how to build a basic tumblelog system (source code in included). So if you have been looking at REST and thinking it was black magic, head over and give it a read!
RESTful Rails. Part I
RESTful Rails have been a a much debated part of the Rails core, since the original restful_rails plugin was merged in to core just over a year ago. But with the improvements that have been made in Rails 2.0, they are here to stay, so it is important to understand what they are, how they work and when to (and when NOT to) use them. This is actually a pretty big topic, and I think it is worth while giving you some background first, so I’ll split the post in twain - Part I is theoretical, Part II is practical. So get your network protocol hats on, and get ready to learn about the inner workings of the language of the web.
REST vs. CRUD
Where would the web be with out acronyms? REST stands for REpresentational State Transfer and describes resources (in our case URLs) on which we can perform actions. CRUD, which stands for Create, Read, Update, Delete, are the actions that we perform. Although, in Rails, REST and CRUD are bestest buddies, the two can work fine on their own. In fact, every time you have written a backend system that allows you to add, edit and delete items …
Upgrading to Rails 2.0. A Recipe
In previous posts, I’m covered some of the updates to Rails 2.0 and how to prepare for Rails 2.0 but haven’t really covered the mechanics of HOW to upgrade to Rails 2.0. So as part of the 6 things to try in Rails this year series, I have compiled a quick recipe that works for me. It probably isn’t the only method, but it works.
1. Fix all of the deprecated warnings
The easiest way to do this is to download Geoffrey Grosenbach’s rake task that I previously mentioned. Copy it to the lib/tasks directory of the app you want to upgrade and run
rake deprecated
This will point you in the direction of any deprecated methods. Find them and fix them.
2. Cleanup your environment
I used to put a lot of code in the enviroment.rb file, which is really a bit of a no-no. To facilitate this, the Rails team introduced the initializers directory where you can add custom code that is automatically loaded at run time. You will need to create the directory now, so run
mkdir config/initializers
Create a new ruby file under that directory and move any custom code, mime types and inflectors from the enviroment.rb files.
3. Update the engine
Even though a lot …
Howto: Write a plug-in
In my previous post, I listed 6 things that you should try in Rails. I also promised some example code to get you started. Since I have already covered installing and upgrading rails, the next cab off the rank is writing a plug-in.
Plug-ins are fantastic - they allow you to abstract away common code into nice little bundles that you can re-use on other projects. Rails even has a built-in system for downloading other peoples plug-ins straight from their SVN repository. With the change over to Rails 2.0, some used-to-be-core functionality has been moved into plug-ins, to clean up the core tree and to allow other developers to release new versions of the plug-ins outside of the regular Rails release cycles.
In this (very brief) tutorial, we will create a plug-in called acts_as_blabbermouth that will print out random quotes . Obviously this plug-in is of little use in the real world, but it should act as a nice demonstration of how plug-ins work.
It’s really easy to generate the boilerplate code thanks to the generate script. To start your plug-in, run the following command in the root of your Rails app:
script/generate plugin acts_as_blabbermouth
You should see an output similar to this:
create vendor/plugins/acts_as_blabbermouth/lib
create …
6 things to try in Rails this year
It seems that blog posts in the first couple of weeks of the new year (happy new year by the way) follow the “x things to do this year” meme as a virtual homage to new years resolutions. Never one to buck a trend, I have prepared this short list of things you should try in Ruby and in Rails - I hope to cover each topic in more detail over the next couple of weeks.
- Install Rails: This is aimed at those of you out there that haven’t tried Ruby on Rails yet. Jump in - have a go, there are plenty of resources out there, and it is fairly easy to install regardless of your platform
- Upgrade to Rails 2.0: I have covered what’s new in Rails 2.0 in a number of my previous posts, and upgrading isn’t really THAT difficult if you follow the steps and fix any deprecation notices.
- Write a plugin: Plugins allow you to re-use common patterns without having to resort to the dreaded cut-and-paste keys. Rails has a built in plugin generator that gives you the skeleton code, all you need to do is to mix-in the right modules - oh, and write the code…
- Try out …
Sponsored Links
SitePoint Marketplace
Buy and sell Websites, templates, domain names, hosting, graphics and more.
SitePoint Kits
Download sample chapters of any of our popular kits.
The Search Engine Marketing Kit, 2.0
The Web Design Business Kit 2.0
The Email Marketing Kit
The Usability Kit
SitePoint Books
Download sample chapters of any of our popular books.
