more info

Media72 Hosting Articles and Tips

Archive for the 'Tips' Category

DNS changes

Wednesday, June 4th, 2008

For all customers experiencing DNS update issues we highly recommend using Open DNS, this is a free service and will enable you to view your sites instantly rather than having to wait for your ISP or local network DNS to be updated.

Javascript auto include rails plugin

Tuesday, May 13th, 2008

This plugin has been updated to include additional functionality. We are very pleased to announce the javascript_auto_include plugin for ruby on rails written by our very own Jamie Dyer. This plugin automatically includes javascript code that is specific to a single view or controller which means you don't have to pass anything to your template telling it which javascript files are needed for each page. Working with unobtrusive javascript in Rails can be somewhat difficult. While Rails default javascript helpers are easy to use they produce javascript that is not unobtrusive. When writing unobtrusive javascript in Rails it's often necessary to include a javascript file that will be used by a single view or controller. This can become problematic, messy and very un-Rails like if not managed well. With the Rails philosophy "convention over configuration" in mind I decided to create a plugin to automatically including javascript files that correspond to the view or controller name mirroring the view structure within the javascripts folder. The javascript_auto_include plugin is born and is probably among the smallest Rails plugins available, aren't all the best plugins tiny? To use the javascript_auto_include firstly install the plugin:


script/plugin install http://kernowsoul.com/svn/plugins/javascript_auto_include
Or if you run EDGE rails or rails 2.1 and above:

script/plugin install git://github.com/kernow/javascript_auto_include.git
The plugin will create the directory "views" within your javascripts directory in which you can place javascript files for auto inclusion. Using javascript_auto_include is simple, in the layout file add < %= javascript_auto_include_tags %> to the header. There are two types of javascript includes, view specific, and controller specific. The first is achieved by creating a folder with the same name as a controller, inside this create a javascript file with the same name as a view. The second type, controller specific, are simply files inside the views folder with the same name as the controller. For example:

/public
  /javascripts
    /views
      articles.js # will be included in all views of the articles controller
      /users
        new.js # will be included in the new view of the users controller
The plugin will also include both controller and view specific javascript at the same time, in this example both users.js and new.js will be included when the new view is loaded.

/public
  /javascripts
    /views
      users.js
      /users
        new.js
If you have any comments or suggestions for improvements we would love to hear them. I may add a generator to make adding new javascript files easy.

Learning Ruby on Rails Fundamentals Without Reading

Wednesday, January 9th, 2008

For all those people, like me, who would rather listen or watch something than read there is now the perfect way to learn Ruby on Rails. Building Web Apps has a new podcast called Learning Rails by Michael Slater and Chris Haupt. It starts at the very beginning teaching you the most basic things about Rails so is perfect for anyone that has no prior Rails experience. They have only got to episode 4 so far but I would assume they will keep going and progress to more advanced topics as time goes on, they say there will be a new episode every 2 weeks. The podcast focuses on the concepts behind Ruby on Rails rather than trying to tech coding. I highly recommend the podcast to anyone new to rails.

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!

Rails Development on Windows

Thursday, November 29th, 2007

Well this one passed us by at Media72 (probably because we are predominantly a mac based company), there is a replacement for Instant rails the in-a-box rails development environment for windows. RubyStack from BitNami is a "Ruby on Rails is a full-stack MVC framework for database-backed web applications that is optimized for programmer happiness and sustainable productivity", so there you go! Included in the download is:

Pretty much everything you need for local Rails development, we especially like the fact that both ImageMagick and Subversion are included in the install as well as everything being very new and up to date. So what are you waiting for? Download RubyStack now and get developing, then signup for one of our fantastic Ruby on Rails hosting packages for maximum developer pleasure.

Getting Real with Ruby on Rails and OS X Leopard

Monday, October 29th, 2007

So Apples new operating system comes with Ruby and Rails pre-installed along with a few standard gems. It does however lack a few things you may need to get your computer running as a development machine. In this mini tutorial we are going to cover: Updating to the latest version of Rails Installing MacPorts Installing ImageMagick Installing the Rmagik gem Installing MySQL Installing the MySQL gem Firstly lets upgrade rails to the latest version of rails, open up a terminal window and enter: sudo gem update rails --include-dependencies Next MacPorts is a package manager for OS X and is needed to install ImageMagick, you can skip straight to the MySQL install if you do not need to manipulate images. I'm not going to explain how to install this as there is excellent instructions on the MacPorts Wiki, be sure to download MacPorts-1.5.0-10.5.dmg for Leopard. After installing MacPorts we can get on with installing the rest of our software, fire up a terminal window and enter the following commands (enter your admin user password when requested): sudo port install tiff -macosx sudo port install ImageMagick sudo gem install rmagick These commands, especially installing ImageMagick, will take some time so it would be a good time to take a break. If all goes well you should now have ImageMagick and the Rmagick gem installed. To install MySQL download the MySQL package labeled 10.4 for your architecture. Then run the mysql-5.0.45-osx10.4-architecture.pkg installer package. Next run the MySQL.prefpane file to install the preference pane. At the current time the MySQL preference pane does not work without modification on Leopard so in the terminal enter: sudo chmod -R 777 /usr/local/mysql/data This gives everyone read/write/execute access to your MySQL data files, this is NOT recommend for anything other than a local development environment and is only intended as a quick fix until MySQL release and updated version for Leopard. Finally, all we need to do now is install the MySQL gem: For intel computers sudo -s ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql For PPC computers sudo -s ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-dir=/usr/local/mysql When asked which version choose the most recent ruby version. If you have any issues getting the MySQL gem to install or run see this Mac OS Forge page. You should now have a fully working Ruby on Rails development installation Rmagick and MySQL.

 

hedges