more info

Media72 Hosting Articles and Tips

Archive for December, 2007

Flexible Fixtures in Rails 2

Wednesday, December 12th, 2007

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!

This article provided by sitepoint.com.


10 Ruby On Rails Plugins You Should Be Using

Sunday, December 9th, 2007

One of Ruby on Rails strengths is how easy it is to extend with Ruby Gems and plugins, becuase you don't have to code everything yourself you can save a lot of time. One problem facing Rails codes is knowing what plugins are out there and how to use them. The following is a list of 10 plugins that should make your coding life much easier and save you a fair bit of time.

  1. attachment_fu - Anyone dealing with file uploads, especially images, should take a look at this plugin, it's a replacement for acts_as_attachment. The plugin is easily configurable and supports storing uploaded files in the file system, database, or on Amazons S3 service. It also supports 3 image manipulation libraries for resizing and altering your uploaded images, Image Science, Mini Magick, and Rmagick.
  2. acts_as_taggable_on_steroids - Tag clouds are not particularly easy to code when you are first starting out. This plugin handles all of the heavy lifting for you including adding and removing tags and even tag cloud calculations.
  3. minus_r - If you are not keen on the prototype javascript library and want to use alternative libraries without replacing the default rails javascript helpers or want to write real javascript in your rjs templates this plugin is for you.
  4. acts_as_ferret - Powerful search plugin that fuilds on the ferret gem for enabling full text searching in your applications. Ferret is a port of Apache's Lucene and enables fast powerful searches with very little code.
  5. white_list - Is essential for any site that allows users to input html to be displayed, this plugin lets you filter out bad HTML tags and attributes to strip out unwanted code and reduce the risk of XSS attacks.
  6. acts_as_ordered - This plugin provides an easy way to find a records neighbours, great if you want to provide previous and next buttons on your site.
  7. BlueCloth/RedCloth - These two are actually gems and convert markdown and textile syntax into HTML markup.
  8. Rspec - All the cool kids are using it these days, why not jump on the fashion bandwagon too? Seriously though, Rspec is a way of specifying how your application "should" behave and then testing it actually "does" what it should.
  9. autotest - This makes testing a breeze, it keeps track of which files you are working on and automatically runs the tests for the file when you save them. When you hook this into growl you can get popup notifications that tell you if your tests passed or failed. Now you can concentrate on coding and forget about remembering to run your tests, works with Rspec and rails built in unit test.
  10. restful_authentication - This replacement for act_as_authenticated offers easy site authentication in a box.
  11. acts_as_rateable - OK we lied, this is the 11th plugin lets call this one a freebie. Add a ratings system to any model, very simple to use neat little plugin.
We hope you found this list useful, try them out and let us know what you think of them. Of course all of the plugins are fully compatible with our Ruby on Rails hosting packages.

Upgrading to Rails 2.0 how to

Sunday, December 9th, 2007

Ben Smith has written some Rails 2 upgrade notes which cover the process of upgrading and existing application to Rails 2.0. Included in the article is a rake task for checking depreciation warnings before you upgrade which is very useful.

Rails 2.0 causing startup errors for some customers

Saturday, December 8th, 2007

After upgrading our servers to Rails 2.0 it has come to our attention this has caused problems for some customers rails applications where the application will fail to start. This will happen when your application is not set to use a specific version of rails and will therefor load the most recent version of rails. On servers where customers have been affected we have removed rails 2.0. This is a temporary measure to give customers time to upgrade their applications. We will be reinstalling rails 2.0 on all servers on Friday 14th December. Read on to see how to make sure your rails application will still work after the upgrade. We are advising all customers to either specifically set the rails version to use in your environment or freeze your rails gems. To set the rails environment in your config edit the config/environment.rb file and un-comment or add the following line: RAILS_GEM_VERSION = '1.2.6' To freeze your rails gems run the following command from your rails application root: rake rails:freeze:gems This will copy all of the files needed to run rails into your vendor/rails directory. If you need to freeze to a specific version of rails run the following command: rake rails:freeze:edge TAG=rel_1-2-6 You may also need to include your other gems within your application, there is an excellent article by Chris Wanstrath called vendor everything that covers how and why you should do this. Lastly, anyone wanting to upgrade their current application to rails 2.0 should first upgrade to rails version 1.2.6 and check for any depreciation warnings before making the leap to rails 2.0. Also watch out for the code that has been removed from rails and is available in plugin form!

Ruby on Rails 2.0 released and installed on all servers

Friday, December 7th, 2007

Thats right folks, today is a big day for Rails and marks the release of version 2.0. For a full run down see DHH's post on the the Ruby on Rails site. We have already upgraded all of our servers to include Rails 2.0.1 so that you guys can get your teeth into it straight away. Sign up with any one of our rails accounts and get instant access to Rails 2.0. How to upgrade? "If you want to move your application to Rails 2.0, you should first move it to Rails 1.2.6. That’ll include deprecation warnings for most everything we yanked out in 2.0. So if your application runs fine on 1.2.6 with no deprecation warnings, there’s a good chance that it’ll run straight up on 2.0. Of course, if you’re using, say, pagination, you’ll need to install the classic_pagination plugin.... And so on and so forth for all the extractions." If you want to keep using Rails 1.x please be sure to set your rails version in your environment.rb file. Happy Rails coding everyone!

 

hedges