This is my second tutorial covering the plugins that we’ve developed.

This tutorial covers the human attribute override plugin.

The plugin allows humanized versions of attributes to be overridden with custom strings to provide a better conversion than human_name may provide.

Why?

The main reason for creating this plugin is that Rails doesn’t always provide an acceptable “humanized” version of an attribute name.

Column.new('num_employees', ...).human_name # => 'Num employees'

You could argue that perhaps the attribute should be named number_of_employees..

Column.new('number_of_employees', ...).human_name # => 'Number of employees'
But this is hardly an acceptable solution for various reasons
  1. The attribute name is too wordy.
  2. Changing an attribute name for the sake of it’s humanized version reading better results in unneeded refactoring.
  3. You’re using a legacy database that uses a specific naming convention.
Read the rest of this entry

Conditional Cache Plugin Tutorial

November 26th, 2007

Updated for Rails 2.1

This is my first of many tutorials to come covering the plugins that we’ve developed.

This tutorial covers the conditional cache plugin, which is actually the first plugin released by Redline.

Why?

By default, the caches_action method allows you to specify one or more actions to apply caching to.

class TestController < ApplicationController
  caches_action :index, :new

  def index
    ...
  end

  def new
    ...
  end
end

In the above example, action caching is being applied to the index and new action. Beyond that we have no additional control over when these actions should be cached or how these actions should be cached. It’s either all or nothing.

So to fix this “all or nothing” problem, the conditional cache plugin adds additonal functionality to the caches_action method by adding 2 additional parameter options that can be passed to the method along with the existing list of actions.

Read the rest of this entry

Conditional Cache updates

October 25th, 2007

I’ve recently fixed a bug in our conditional cache plugin that I introduced while making it compatible with Rails 1.2.4.

The bug has been fixed and the plugin also works with Rails 1.2.5.

The bug was causing the wrong cache paths to be created, so if you updated the plugin, update again ASAP.

The conditional cache plugin has been updated to be compatible with Rails 1.2.4. If you’re still using a previous version of Rails, there is no need to upgrade the plugin.

Update: Compatible with Rails 1.2.5 now

New in_place_editor plugin

July 23rd, 2007

I have just released a new plugin that can be found at http://agilewebdevelopment.com/plugins/improved_in_place_editor

This plugin allows all options of the Ajax.InPlaceEditor control to be set. This will also work with the new rewrite of the control, which is currently in the scriptaculous trunk.

This plugin replaces the current rails version of in_place_editor and is drop-in compatible.

Quick summary (more details at the url above)...

Missing options such as onFailure can now be specified…

<%= in_place_editor 'field_id', :on_failure => "function(transport) {alert(\"Error: \" + transport.responseText.stripTags());}" %>

Some options require quoting to be valid in the JS, such as :highlight_color.[1]

1 :highlight_color is the option name for the rewritten version of the control, :highlightcolor is the old name.

The 2 ways to specify the option are…

1) Manually quote the option
<%= in_place_editor 'field_id', :highlight_color => "’#000000’" %>
2) Use the :quoted option
<%= in_place_editor 'field_id', :quoted => {:highlight_color => ’#000000’} %>

Check out our other available plugins at http://agilewebdevelopment.com/plugins/owner/72

Updated conditional_cache plugin

February 20th, 2007

Just a quick note... I've updated our conditional_cache plugin (http://www.agilewebdevelopment.com/plugins/conditional_caching) to be more in sync with the current rails cache code that this plugin overrides.

Enjoy!