Updated for will_paginate 2.3.x

So you’re using the will_paginate plugin and want to use remote AJAX links. You’re not using the will_paginate plugin? Simply install it with…

script/plugin install svn://errtheblog.com/svn/plugins/will_paginate

will_paginate is an alternative to the classic_pagination plugin, which is the pagination plugin that basically took the pre Rails 2.0 pagination implementation and packaged it in plugin form. I won’t discuss the differences between the two plugins here, but there’s a good video explaining the two from Railscasts here.

Out of the box, will_paginate doesn’t allow remote AJAX links for page links, so I’ll show you an easy way to add such functionality…

Read the rest of this entry

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

Selection javascript lib

October 26th, 2007

I’ve created a basic first draft for a javascript selection library. The library allows the user to select many elements on a web page with a simple mouse drag.

I call this version 0.1 as it has only been tested in Firefox and has some minor issues that need some cleaning up, but I figured I might as well make it public so people can take a look, try it, give feedback, or send patches.

You can grab the files and see a demo of it here

The library requires prototype and builder… both of which come with Rails.

Patches and feedback are welcome.

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!

from_db ActiveRecord extension

January 4th, 2007

Here's a really simple, but useful ActiveRecord extension I wrote.

class ActiveRecord::Base
  def from_db
    self.class.find self.id
  end
end

What this does is reload the current object from the database and returns it. Read more about how this can be useful...

Read the rest of this entry