RSS ? Recent Blog Posts

Blogs » Ruby on Rails
 

Get on Track

: Ruby on Rails Blog

Subversion gits the last train

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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

by Myles Eftos

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.

  1. 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
  2. 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.
  3. 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…
  4. Try out …
 

Flexible Fixtures in Rails 2

by Myles Eftos

As Matt Magain pointed out yesterday, Rails 2.0 is now gold! Not a lot has changed feature wise from the PR (makes sense - features were frozen at that point), although it seems that the new improvements to fixtures managed to slip in to the final version.

Rather than having to map foreign keys in your fixtures using id numbers, you can use fixture names, which makes life a whole lot easier. So you can now write:

users.yml

joe_blogs:
id: 1
first_name: Joe
last_name: Blogs
mary_smith:
id: 2
first_name: Mary
last_name: Smith

websites.yml

website_1
id: 1
user: joe_blogs
url: “http://www.joeblogs.com”

website_2
id: 2
user: mary_smith
url: “http://mary.smith.id.au”

which obviously makes a lot more sense to a human reading it, especially when you have a large number of fixtures across many models.

Let me join Matt in congratulating the Rails core dev team for achieving this milestone - roll on Rails 3!

 

Rails 2.0.1 Released!

by Matthew Magain

While the SitePoint crew were busy sunning themselves by the pool on our annual Xmas trip, the Rails core team packaged up version 2.0 of the Ruby on Rails framework and released it on the world. I expect the team probably had a fairly stressful weekend putting out a few fires (understandable given this is a major release). The result of their hard work is that, after only a couple of days, version 2.0.1 is already upon us.

If you’re using Ruby Gems, update your Rails install by typing:

gem install rails –include-dependencies

Our resident Ruby guru Myles Eftos has covered what’s new in Rails 2 and how you can best prepare for upgrading, so be sure to read up before you take the plunge.

 

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Logo Design, Web page Design and more!

99designs

  • Custom logo designs created ‘just for you’.
  • Pick the design you like best.
  • Only pay if you’re satisfied with the result.

The Web Site Revenue Maximizer
The Ultimate HTML Reference

Book: The Ultimate HTML Reference

The most complete and up-to-date HTML Encyclopedia money can buy.

Free eBook! Firefox Revealed