Ruby on Rails

Making a form reset button in Rails

Tags: 

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:
[source:ruby]
'reset', :id => 'reset_button', :type => "reset" }) %>
[/source]
which will create the following:
[source:html]

[/source]
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

Tags: 

A small tip for anyone trying to install Radiant on their Dreamhost.com 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.:
[source:ruby]
ENV['RAILS_ENV'] = 'production'
ENV["GEM_HOME"]="/home/myaccount/.gems"
ENV["GEM_PATH"]="/home/myaccount.gems:/usr/lib/ruby/gems/1.8"
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'
RailsFCGIHandler.process!
[/source]

Radiant is a great CMS

Tags: 

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:
Mephisto

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

RailFrog

  • 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

Tags: 

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:
[source:ruby]
:empty, :confirm => "Really empty your cart?" %>
[/source]
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.:
[source:ruby]
:empty}, {:confirm => "Really empty your cart?"} %>
[/source]

Pages

Subscribe to Ruby on Rails