Ruby on Rails

Making a form reset button in Rails


Rails doesn't have reset_tag to automatically make a form reset button, instead you have to take a slightly different route. To make a form reset button in Rails you simply do this:
'reset', :id => 'reset_button', :type => "reset" }) %>
which will create the following:

The important part here is the :type argument, which override's Rails' default of "submit" for the submit_tag. Then, to tidy it up a little I override the :name, which defaults to "commit", and give it a useful id attribute.

Et voila!

RadiantCMS on Dreamhost


A small tip for anyone trying to install Radiant on their account.

The original instructions I found said that three ENV lines that had to be added to the dispatch.fcgi file had to be before the RailsFCGIHandler.process! line. Well it turns out they have to be before the require lines, e.g.:
ENV['RAILS_ENV'] = 'production'
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'

Radiant is a great CMS


I just wanted to pass on the meme on a great RoR-based CMS - Radiant. It is OSS, very stable, fairly actively developed and has a really good plugin system.

While searching for a RoR-based CMS I looked at it a few others:

  • Development has dried up due to the developers not having the time to continue it.
  • No support for snippets (see below).


  • Development seems to have dried up, the last messages on the blog were from 2006 and talked about a complete rewrite, which is usually a bad sign IMHO.

Some of the benefits that got me hooked on Radiant include:

  • snippets (keep your content DRY),
  • separate layouts vs content,
  • layouts support custom mimetypes (ensure your RSS feeds get the right content type),
  • the ability to structure the pages in a heirarchy,
  • a set of custom tags for manipulating the content,
  • built-in support for textile.
  • Some existing plugins that make life evey easier, specifically Google Analytics and Virtual Domains (multiple sites from one install!).

The few limitations I see are:

  • the plugin system needs to be improved to make extending the pages list easier,
  • the blog-like functionality needs improving,
  • some of the documentation needs work.

I've already used it on one site and am working to move all of our more static sites over to it - the less static ones will have to wait until I write a few plugins.

button_to HTML options not completely intuitive


While working on a site in Rails tonight I was adding a button_to that I wanted a JS confirmation requester. Well, based on my albeit beginner knowledge of Rails I thought the following would work:
:empty, :confirm => "Really empty your cart?" %>
As it turned out this wouldn't work, it kept adding "?confirm=Really empty your cart?" to the URL instead of doing a popup. A bit of fiddling later I realized that to work correctly the additional arguments to button_to need to be arrays, e.g.:
:empty}, {:confirm => "Really empty your cart?"} %>


Subscribe to Ruby on Rails