<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scott Rutherford &#187; ajax</title>
	<atom:link href="http://blog.thatsuseful.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thatsuseful.com</link>
	<description>Life on and off the Rails</description>
	<lastBuildDate>Wed, 21 Jul 2010 16:35:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ActiveScaffold RC1 Released</title>
		<link>http://blog.thatsuseful.com/2007/03/10/activescaffold-rc1-released/</link>
		<comments>http://blog.thatsuseful.com/2007/03/10/activescaffold-rc1-released/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 05:24:46 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/activescaffold-rc1-released</guid>
		<description><![CDATA[So after a lot of work (mostly done by the three other members of the team &#8211; Richard White, Lance Ivy and Ed Moss) the new shiny version of AjaxScaffold has reached RC1 and is available under its new name ActiveScaffold. Richard White gives a bit more info about it on his blog. This will [...]]]></description>
			<content:encoded><![CDATA[<p>So after a lot of work (mostly done by the three other members of the team &#8211; Richard White, Lance Ivy and Ed Moss) the new shiny version of AjaxScaffold has reached <span class="caps">RC1</span> and is available under its new name <a href="http://www.activescaffold.com">ActiveScaffold</a>.</p>
<p><a href="http://www.height1percent.com">Richard White</a> gives a bit more info about it on his <a href="http://www.height1percent.com/articles/2007/03/09/activescaffold-rc1-released">blog</a>.</p>
<p>This will pretty much draw to a close this blog being used for the docs as AjaxScaffold will get an <span class="caps">EOL</span> stamp once ActiveScaffold reaches v1.0. So thank you to all who have given us feedback and supported the project so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2007/03/10/activescaffold-rc1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AjaxScaffold 3.2.3 Released</title>
		<link>http://blog.thatsuseful.com/2007/01/23/ajaxscaffold-3-2-3-released/</link>
		<comments>http://blog.thatsuseful.com/2007/01/23/ajaxscaffold-3-2-3-released/#comments</comments>
		<pubDate>Tue, 23 Jan 2007 07:03:34 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ajaxscaffold-3-2-3-released</guid>
		<description><![CDATA[We released a new version of AS today which fixes the issues with prototype and rico when using Rails 1.2.1. For details of the issue you can see my previous post. This is simply a fix for the v3 plugin and contains none of the new (and very exciting stuff) coming in v4. It should [...]]]></description>
			<content:encoded><![CDATA[<p>We released a new version of AS today which fixes the issues with prototype and rico when using Rails 1.2.1. For details of the issue you can see my previous post.</p>
<p>This is simply a fix for the v3 plugin and contains none of the new (and very exciting stuff) coming in v4. It should be a straight upgrade for anyone on 3.2.2.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2007/01/23/ajaxscaffold-3-2-3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AjaxScaffold and Rails 1.2.1</title>
		<link>http://blog.thatsuseful.com/2007/01/22/ajaxscaffold-and-rails-1-2-1/</link>
		<comments>http://blog.thatsuseful.com/2007/01/22/ajaxscaffold-and-rails-1-2-1/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 10:08:56 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ajaxscaffold-and-rails-1-2-1</guid>
		<description><![CDATA[There is an issue with the latest release of Rails and AjaxScaffold. Well actually the problem is in a conflict between Prototype and Rico Corner, if you find that all the AJAX stops working &#8211; lots of spinning indicators and not much else you have three choices, wait a little and we will likely release [...]]]></description>
			<content:encoded><![CDATA[<p>There is an issue with the latest release of Rails and AjaxScaffold. Well actually the problem is in a conflict between Prototype and Rico Corner, if you find that all the <span class="caps">AJAX</span> stops working &#8211; lots of spinning indicators and not much else you have three choices, wait a little and we will likely release an update, or if you are impatient / desperate for a fix you can use the following patch for prototype or you can remove the Rico Corner include&#8230;&#8230;</p>
<p>            <span id="more-54"></span></p>
<h2>Patch Prototype</h2>
<p>Simply open prototype.js and around line 915 replace this:</p>
<pre>
for (var name in headers)
  this.transport.setRequestHeader(name, headers[name]);
</pre>
<p>with this:</p>
<pre>
for( var name in headers ) {
  if( typeof( headers[name] ) != 'function' ) {
    this.transport.setRequestHeader(name,headers[name]);
  }
}
</pre>
<p>and all should be well again.</p>
<h2>Remove Rico</h2>
<p>Open up the ajax_scaffold_plugin.rb file in vendor/plugins/ajaxscaffoldp (or wherever it was installed) and at the bottom remove the &#8216;rico_corner&#8217; include from this method:</p>
<pre>
def ajax_scaffold_includes
  js = javascript_include_tag(:defaults, 'rico_corner', 'ajax_scaffold', 'dhtml_history')
  css = stylesheet_link_tag('ajax_scaffold')
  js + "\n" + css
end
</pre>
<p>You should also remove the call to Rico.corner in table.rhtml, now all should function again just without rounded corners&#8230;..
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2007/01/22/ajaxscaffold-and-rails-1-2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Columns with Ajax Scaffold</title>
		<link>http://blog.thatsuseful.com/2006/10/28/dynamic-columns-with-ajax-scaffold/</link>
		<comments>http://blog.thatsuseful.com/2006/10/28/dynamic-columns-with-ajax-scaffold/#comments</comments>
		<pubDate>Sat, 28 Oct 2006 06:11:06 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/dynamic-columns-with-ajax-scaffold</guid>
		<description><![CDATA[I&#8221;ve been asked a couple of times how to dynamically setup the columns displayed by the AS plugin dependant on the permissions of the user, so I though a quick post would be a good idea. Basically its very simple, you simply define a hash of all the columns you potentially wish to display keyed [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8221;ve been asked a couple of times how to dynamically setup the columns displayed by the AS plugin dependant on the permissions of the user, so I though a quick post would be a good idea.</p>
<p>Basically its very simple, you simply define a hash of all the columns you potentially wish to display keyed by the column name, so something like:</p>
<pre>
@@columns_hash[:user] = ScaffoldColumn.new(..)
@@columns_hash[:foo] = ScaffoldColumn.new(:name =&gt; 'bar')
</pre>
<p>Then define a before_filter along the lines of:</p>
<pre>
before_filter :create_columns, <img src='http://blog.thatsuseful.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt; ['table', 'update_table']
</pre>
<p>            <span id="more-43"></span></p>
<p>Finally all you need to do is write the create_columns method to assign the appropriate columns dependant on the user:</p>
<pre>
def create_columns
  if user.is_administrator
    @@scaffold_columns = [ @@columns_hash[:user], @@columns_hash[:foo] ]
  else
    @@scaffold_columns = [ @@columns_hash[:user] ]
  end
end
</pre>
<p>A bit contrived but you get the idea.</p>
<p>This method should continue working in the upcoming 4.0 version of the plugin (associations, search, all sorts of loveliness in that&#8230;..) however I think it will have been refined a bit to get rid of the class variables. But for now, it should solve the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/10/28/dynamic-columns-with-ajax-scaffold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Scaffold Plugin v3.2.2 Released</title>
		<link>http://blog.thatsuseful.com/2006/10/02/ajax-scaffold-plugin-v3-2-2-released/</link>
		<comments>http://blog.thatsuseful.com/2006/10/02/ajax-scaffold-plugin-v3-2-2-released/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 15:01:19 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ajax-scaffold-plugin-v3-2-2-released</guid>
		<description><![CDATA[I released a new version of the plugin today that fixes a few outstanding issues and adds 3 new extension points. The main things that have been fixed are: Single table inheritance now works Legacy table names are now supported The table formats properly under IE The 3 extra extra extension points are do_new do_edit [...]]]></description>
			<content:encoded><![CDATA[<p>I released a new version of the plugin today that fixes a few outstanding issues and adds 3 new extension points. The main things that have been fixed are:</p>
<ol>
<li>Single table inheritance now works</li>
<li>Legacy table names are now supported</li>
<li>The table formats properly under IE</li>
</ol>
<p>The 3 extra extra extension points are</p>
<ol>
<li>do_new</li>
<li>do_edit</li>
<li>do_delete</li>
</ol>
<p>I will update the <a href="http://blog.caronsoftware.com/articles/2006/09/06/extending-the-ajax-scaffold-plugin">post on extending the plugin</a> to fully cover these new features.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/10/02/ajax-scaffold-plugin-v3-2-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Scaffold Plugin v3.2.0 Released</title>
		<link>http://blog.thatsuseful.com/2006/09/13/ajax-scaffold-plugin-v3-2-0-released/</link>
		<comments>http://blog.thatsuseful.com/2006/09/13/ajax-scaffold-plugin-v3-2-0-released/#comments</comments>
		<pubDate>Wed, 13 Sep 2006 10:08:41 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ajax-scaffold-plugin-v3-2-0-released</guid>
		<description><![CDATA[So before I head off for the first event on my Rails Conf Europe calendar &#8211; Pizza on Rails (sponsored by Cominded). I thought I would mention that Richard White and myself have now released version 3.2.0 of the ajax scaffold plugin. This fixes a few bugs and a compatibility problem with generators before version [...]]]></description>
			<content:encoded><![CDATA[<p>So before I head off for the first event on my Rails Conf Europe calendar &#8211; <a href="http://www/pizzaonrails.com">Pizza on Rails</a> (sponsored by <a href="http://www.cominded.com">Cominded</a>). I thought I would mention that <a href="http://www.height1percent.com">Richard White</a> and myself have now released version 3.2.0 of the ajax scaffold plugin. This fixes a few bugs and a compatibility problem with generators before version 3.1.6.</p>
<p>The <a href="http://ajaxscaffold.stikipad.com">wiki</a> contains links to various bits of documentation for both the plugin and the generator. Plugin specific posts from myself can be found <a href="http://blog.caronsoftware.com/articles/category/ajax-scaffold-plugin">here</a></p>
<p>Right, free beer and pizza&#8230;&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/09/13/ajax-scaffold-plugin-v3-2-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FCKeditor Plugin 0.2.3 Released</title>
		<link>http://blog.thatsuseful.com/2006/09/11/fckeditor-plugin-0-2-3-released/</link>
		<comments>http://blog.thatsuseful.com/2006/09/11/fckeditor-plugin-0-2-3-released/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 06:05:44 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[FCKeditor]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/fckeditor-plugin-0-2-3-released</guid>
		<description><![CDATA[This release is basically a bug fix. The only really change is to apply the patch kindly provided by Nicola Piccinini which sorts out an issue with file upload from inside the resource manager. There are a couple of other changes to do with the install and version numbers, but that is all internal to [...]]]></description>
			<content:encoded><![CDATA[<p>This release is basically a bug fix. The only really change is to apply the patch kindly provided by <a href="http://superfluo.org">Nicola Piccinini</a> which sorts out an issue with file upload from inside the resource manager.</p>
<p>There are a couple of other changes to do with the install and version numbers, but that is all internal to the plugin.</p>
<p><a href="http://fckeditor.caronsoftware.com">demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/09/11/fckeditor-plugin-0-2-3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FCKeditor Plugin 0.2.2 Released</title>
		<link>http://blog.thatsuseful.com/2006/09/08/fckeditor-plugin-0-2-2-released/</link>
		<comments>http://blog.thatsuseful.com/2006/09/08/fckeditor-plugin-0-2-2-released/#comments</comments>
		<pubDate>Fri, 08 Sep 2006 09:22:44 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[FCKeditor]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/fckeditor-plugin-0-2-2-released</guid>
		<description><![CDATA[There is a new version of the FCKeditor Rails plugin available details of how to get it and a demo are here. This version fixes a problem with having multiple editors open at once on the same page and also adds a helper to allow multiple editors on the same Ajax form. This also now [...]]]></description>
			<content:encoded><![CDATA[<p>There is a new version of the FCKeditor Rails plugin available details of how to get it and a demo are <a href="http://fckeditor.caronsoftware.com">here</a>.</p>
<p>This version fixes a problem with having multiple editors open at once on the same page and also adds a helper to allow multiple editors on the same Ajax form. This also now works with static html forms but you can just use the standard form helpers for that.</p>
<p>            <span id="more-28"></span></p>
<p>To create an ajax form using multiple editors use the fckeditor_form_remote_tag helper and pass the :editors option. This takes an hash of model symbol keys with each having an array as its value. The array should contain the list of fields that will have editors attached to them.</p>
<pre>
&lt;%= fckeditor_form_remote_tag :url =&gt; some_great_url,
     :editors =&gt; { :multinote =&gt; ['text1', 'text2'] } %&gt;

    &lt;%= fckeditor_textarea( "multinote", "text1", :ajax =&gt; true ) %&gt;
    &lt;%= fckeditor_textarea( "multinote", "text2", :ajax =&gt; true ) %&gt;

&lt;%= end_form_tag %&gt;
</pre>
<p>You can of course use the same helper for a single editor or for static html forms as it is a bit neater than having to declare the :before javascript method yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/09/08/fckeditor-plugin-0-2-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the Ajax Scaffold Plugin</title>
		<link>http://blog.thatsuseful.com/2006/09/06/extending-the-ajax-scaffold-plugin/</link>
		<comments>http://blog.thatsuseful.com/2006/09/06/extending-the-ajax-scaffold-plugin/#comments</comments>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin</guid>
		<description><![CDATA[AjaxScaffold has been deprecated in favour of ActiveScaffold The aim of this post is to show how to extend or replace the default functionality of the Ajax Scaffold plugin (ASp). I will go over two areas, firstly how you filter the dataset the table displays, and secondly the methods you can override to really gain [...]]]></description>
			<content:encoded><![CDATA[<p><span style=\"background-color: #ff8; font-weight: bold; padding: 2px 5px;\">AjaxScaffold has been deprecated in favour of <a href=\" http://www.activescaffold\">ActiveScaffold</a></span></p>
<p>The aim of this post is to show how to extend or replace the default functionality of the Ajax Scaffold plugin (ASp). I will go over two areas, firstly how you filter the dataset the table displays, and secondly the methods you can override to really gain control.</p>
<p>            <span id="more-27"></span></p>
<h2>Simple Filtering of the Dataset</h2>
<p>In order to filter the data that the table displays you need to simply override a single method (for each model) in your controller.</p>
<p><strong>conditions_for_{table_name}_collection</strong></p>
<p>This method is expected to return the same array that the Rails <strong>find()</strong> method accepts as its :conditions parameter.</p>
<p>Lets take a simple user model as an example. The db table has the following columns:  id, name, password, employer_id where the employer_id represents a has-one relationship to the user&#8217;s employer (represented by another table). Now lets say we only want to see users from the current employer in our table, then all we need to do is define the following method in our controller:</p>
<pre>
def conditions_for_users_collection
  [ 'employer_id = ?', params[:current_employer] ]
end
</pre>
<p>This of course assumes that the current request defines :current_employer as the employer&#8217;s id.</p>
<p>You can use any conditional statements you like, if they would work in the Rails <strong>find()</strong> method, they will work here.</p>
<h2>More Complex Filtering</h2>
<p>At a lower level the collection used by the table is provided by a combination of three methods:</p>
<ol>
<li>count_{table_name}_collection(model, options)</li>
<li>page_and_sort_{table_name}_collection(model, options, paginator)</li>
<li>page_and_sort_{table_name}_collection_with_method(model, options, paginator)</li>
</ol>
<p>These methods represent a slightly extended version of the methods found in the Rails paginator. The first two are called for any normal page or sort (i.e not using a ScaffoldColumn defined using the :sort parameter) and the last is called only for ScaffoldColumns defined with, wait for it, the :sort parameter.</p>
<p>For example lets say we have a set of Report objects that are displayed using the following column definitions:</p>
<pre>
@@scaffold_columns = [
    AjaxScaffold::ScaffoldColumn.new(Report, {
        :name =&gt; "title",
        :eval =&gt; "row.current_definition.title",
        :sort =&gt; 'current_definition.title'}),
    AjaxScaffold::ScaffoldColumn.new(Report, {
        :name =&gt; "viewed",
        :eval =&gt; "row.views",
        :sort =&gt; 'views' }),
]
</pre>
<p>We also have defined a method that returns the reports for a particular project, or the reports for a project in a particular category (all of which would be difficult to do with a simple :conditions statement):</p>
<pre>
def get_reports
  project = get_project
  reports = project.reports

  if request.post?
    selected_category = params[:category]
    reports = project.reports_for_category(selected_category) if selected_category
  end
  reports
end
</pre>
<p>We could then define the three methods above as follows (in ReportsController.rb):</p>
<pre>
def count_reports_collection(model, options)
  get_reports.size
end

def page_and_sort_reports_collection_with_method(model, options, paginator)
  collection = get_reports
  order_parts = options[:order].split(' ')
  sort_collection_by_method(collection, order_parts[0], order_parts[1]).slice(paginator.current.offset,options[:per_page])
end

def page_and_sort_reports_collection(model, options, paginator)
  page_and_sort_reports_collection_with_method(model, options, paginator)
end
</pre>
<p>This would cause every sort / page to use the <strong>with_method</strong> methods, as we need due to all columns using the :sort parameter. Our count would come from our get_reports method and everything should work as expected.</p>
<h2>Other Extension Points</h2>
<p>Here are some of the other methods that you can override to change the behaviour of the scaffold, its probably a good idea to actually look at the plugin code to see how each method is used, although some are pretty self explanatory.</p>
<p>In all of these {prefix} is defined as {table_name}_.That is the table name with an underscore appended. {suffix} is defined as _{model_name_in_lower_case}. That is the model name in lower case with an underscore prepended. These are only required in multi table scenarios (I have written it like this here to match the actual code). The reason for doing this is to give <span class="caps">CRUD</span> like methods when only using a single table.</p>
<p><strong>Default Sort Column</strong></p>
<p>By default the rows are sorted using the primary key, id. To change this you can override: default_sort / default_{prefix}sort</p>
<pre>
def default_{prefix}sort
   "users.name"
end
</pre>
<p><strong>Default Sort Direction</strong></p>
<p>To change this from &#8216;asc&#8217; you can override: default_sort_direction / default_{prefix}sort_direction. The only other possible return value is &#8220;desc&#8221;.</p>
<pre>
def default_{prefix}sort_direction
   "desc"
end
</pre>
<p><strong>Create</strong></p>
<p>If you want to change the default behaviour when a model is created you can override the following method which is called internally:</p>
<pre>
def do_create#{suffix}
    @user = User.new(params[:user])
    @successful = @user.save
end
</pre>
<p><strong>Update</strong></p>
<p>If you want to change the default behaviour when a model is updated you can override the following method which is called internally:</p>
<pre>
def do_update#{suffix}
    @user = User.find(params[:id])
    @successful = @user.update_attributes(params[:user])
end
</pre>
<p><strong>Table</strong></p>
<p>To add custom behvaiour to the table rendering you can use this method. This is really to add functionality, you still need to call the methods as shown or things may go a little wrong:</p>
<pre>
def #{prefix}table
    self.#{prefix}table_setup

    OTHER CODE GOES IN HERE

    render#{suffix}_template(:action =&gt; 'table')
end
</pre>
<p><strong>Added in 3.2.2</strong></p>
<p><strong>New</strong></p>
<p>Called before the new form appears</p>
<pre>
def do_new#{suffix}
  @user = User.new
  @successful = true
end
</pre>
<p><strong>Edit</strong></p>
<p>Called to find the object to edit</p>
<pre>
def do_edit#{suffix}
  @user = User.find(params[:id])
  @successful = !@user.nil?
end
</pre>
<p><strong>Destroy</strong></p>
<p>Called to find and destroy an object</p>
<pre>
def do_destroy#{suffix}
  @successful = User.find(params[:id]).destroy
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/09/06/extending-the-ajax-scaffold-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Columns for the Ajax Scaffold Plugin</title>
		<link>http://blog.thatsuseful.com/2006/09/05/defining-custom-columns-with-ajax-scaffold-plugin/</link>
		<comments>http://blog.thatsuseful.com/2006/09/05/defining-custom-columns-with-ajax-scaffold-plugin/#comments</comments>
		<pubDate>Tue, 05 Sep 2006 13:19:38 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/defining-custom-columns-with-ajax-scaffold-plugin</guid>
		<description><![CDATA[AjaxScaffold has been deprecated in favour of ActiveScaffold One of the first things you will probably notice with the Ajax Scaffold plugin (ASp) is that works great if all you want to do is display a table showing all the fields a model has to offer. However, suppose we want to produce a table showing [...]]]></description>
			<content:encoded><![CDATA[<p><span style=\"background-color: #ff8; font-weight: bold; padding: 2px 5px;\">AjaxScaffold has been deprecated in favour of <a href=\" http://www.activescaffold\">ActiveScaffold</a></span></p>
<p>One of the first things you will probably notice with the Ajax Scaffold plugin (ASp) is that works great if all you want to do is display a table showing all the fields a model has to offer. However, suppose we want to produce a table showing values that come from user defined methods on a model.</p>
<p>For example lets take a User model with the following fields:  name, password, created_at, number_of_logins. To create a table that simply shows these fields is easy, simply add the following to the UsersController:</p>
<pre>
ajax_scaffold: user
</pre>
<p>but suppose we want one of the columns to contain only the name and the average number of logins per week / per month / per year&#8230;.</p>
<p>            <span id="more-26"></span></p>
<p>To this end we have coded up following 3 methods in our model:</p>
<pre>
def logins_per_month
  some great code
end

def logins_per_week
...
end

def logins_per_year
..
end
</pre>
<p>Now to get ASp to use these as columns we need to declare a set of AjaxScaffold::ScaffoldColumn objects. N.B <strong>the generator does this in the model &#8211; the plugin does it in the controller</strong></p>
<p>Before going into the detail of how to implement this example lets take a quick look at the ScaffoldColumn object.</p>
<h2>AjaxScaffold::ScaffoldColumn</h2>
<p>This class is used internally (although we will override this in a min) by ASp (and the generator) to create the columns to be displayed. Its constructor takes the following form:</p>
<p><strong>AjaxScaffold::ScaffoldColumn.new(class name, options)</strong></p>
<p>The constructor of the ScaffoldColumn object takes the following options:</p>
<p><strong>name</strong> &#8211; declares the column on the model we are defining, this is the only required value and will be used to infer everything else  unless explicitly defined.</p>
<p><strong>label</strong> &#8211; represents the display name of the column. This will be displayed as the titleized version of the name unless given explicitly.</p>
<p><strong>class_name</strong> &#8211; this defines a css class name to be appended to column class declaration.</p>
<p><strong>eval</strong> &#8211; is where we define the method to be called. It can be declared as row.method_name, where &#8220;row&#8221; means the actual string &#8220;row&#8221;, or as model_name.method_name</p>
<p><strong>sort_sql</strong> &#8211; defines the table column to be used for sorting, usually the same as the <span class="caps">SQL</span> column name</p>
<p><strong>sort</strong> &#8211; used to define a class method to be used for sorting (like the logins_per_year)</p>
<h2>Users Example (single table on the page)</h2>
<p>So back to the example, with only one table on the page (i.e the :suffix option not passed to the plugin) our custom columns can be defined by adding the following declaration to the controller:</p>
<pre>
@@scaffold_columns = [
   Array of ScaffoldColumn objects here
]
</pre>
<p>Seems easy enough, what about the columns. Ok so we have 4 columns we want displaying the first is the name of the user and then the 3 with our user defined methods. This leads to the following:</p>
<pre>
@@scaffold_columns = [
        AjaxScaffold::ScaffoldColumn.new(User, { :name =&gt; "name" }),
        AjaxScaffold::ScaffoldColumn.new(User, { :name =&gt; "per week",
          :eval =&gt; "row.logins_per_week", :sort =&gt; 'logins_per_week' }),
        AjaxScaffold::ScaffoldColumn.new(Report, { :name =&gt; "per month",
          :eval =&gt; "row.logins_per_month", :sort =&gt; 'logins_per_month' }),
        AjaxScaffold::ScaffoldColumn.new(Report, { :name =&gt; "per year",
          :eval =&gt; "row.logins_per_year", :sort =&gt; 'logins_per_year' })
]
</pre>
<p>It is worth noting that if you had an association on the User model, lets say Address (in a has relationship) you could access that information for the sort by defining something like:</p>
<pre>
AjaxScaffold::ScaffoldColumn.new(User, { :name =&gt; "postcode",
   :eval =&gt; "row.address.postcode", :sort =&gt; 'address.postcode' })
</pre>
<p>This will work to as many levels as you see fit to play with.</p>
<h2>Users Example (multiple tables on the page)</h2>
<p>With multiple tables on a page (:suffix passed as true), you need to update the code above to include the prefix users_:</p>
<pre>
@@users_scaffold_columns = [
.......
]
</pre>
<p>You can then do the same for any other tables in the page.</p>
<h2>Totalling Custom Columns</h2>
<p>To cause totals of any of your columns to be calculated and displayed simply add a second array containing the names of the columns you want to total:</p>
<pre>
@@scaffold_column_totals = ['per month', 'per year']
</pre>
<p>Remember to use the prefix if you have more than one table in the controller.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/09/05/defining-custom-columns-with-ajax-scaffold-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
