ActiveScaffold jqplot and FieldSearch

Leave a comment

Every tried to use a graphic library with ActiveScaffold and fieldsearch?

Just a quick introduction how you may integrate jqplot Activescaffold and field_search.

Add a new layout which integrates jqplot

javascript_include_tag 'jquery.jqplot.min'
javascript_include_tag 'jqplot.highlighter.min'
javascript_include_tag 'jqplot.cursor.min'
javascript_include_tag 'my_chart_statistic'
stylesheet_link_tag 'jquery.jqplot.min'

Configure you Controller to disable all actions except field_search and configure field_search as you like:

layout "charts"
conf.list.pagination = false

conf.actions.exclude :show
conf.actions.exclude :update
conf.actions.exclude :create
conf.actions.exclude :search
conf.actions < {‘number’ => 1,
‘from’ => ”,
‘to’ => ”,
‘unit’ => “YEARS”,
‘range’ => ‘TODAY’,
‘opt’ => ‘PAST’},
:col2 => {‘opt’ => ‘%?’}

Override _list.html.erb view for your controller

<p class="filtered-message-graph" >
'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %>

<div id=”my-chart” data-records=””>


Configure jqplot to displa your graph (my_chart_statistic.js in javascript dir)

var update_chart = function() {
var records = $("#my-chart").data("records");
var bcsPlot = $.jqplot('my-chart', [records],
min: 0,
tickOptions: {
showGridline: false
min: 0,
max: 5,
ticks:[1.00, 1.50, 2.00, 2.50, 3.0, 3.50, 4.0, 4.5, 5.0],
tickOptions: {
formatString: '%.2f' // format string to use with the axis tick formatter
highlighter: {
show: true,
tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {

var col2 =[seriesIndex][pointIndex][2];
var col3 =[seriesIndex][pointIndex][3];
var col4 =[seriesIndex][pointIndex][4];

var html = ”

col2: “;
html += col2;
html += “col3: “;
html += col3;
html += “col4: “;
html += col4;
html += “


return html;
show: true,
// Series options are specified as an array of objects, one object
// for each series.
// Don’t show a line, just show markers.
// Make the markers 7 pixels with an ‘x’ style
markerOptions: { size: 7, style:”x” }


$(document).on(‘ajax:complete’, ‘form.as_form’, function(event) {



ActiveScaffold: Confirmation of Actionlinks

Leave a comment

Today I was called by a user stating that something really bad happened. He clicked an actionlink accidently and now data is a mess.
Well after some investigation I ve asked him: Why did you even press ok in confirmation dialog?
The answer was quite a surprise for me cause he told me that there was nt any confirmation dialog.
First thought of any developer, user is lying, but well sadly I have to admit that he was right. He had javascript disabled and I had to accept that apparently activescaffold was performing the action without a confirmation.

I ve fixed that today. If you update your activescaffold to latest version, you are save.
However, application will display missing routing error in these special cases.

Let me show you how you may change your application to work as expected if javascript is disabled.
In my post Actionlink response and ignore I ve described an easy way to respond to actions triggered by an actionlink. I will use it as a base for my example.

First step: Adding a new route

 put :fire, : on => :member
 get :fire, : on => :member 

As an alternative you might also add non resource routes, it s important to add them BEFORE the resource routes.

match 'players/:id/fire' => 'players#fire', :via => [:get, :put] 
resources :player

Second step: Rewrite action method fire in players controller

def fire 
  process_action_link_action do |record| 
      record.update_attributes!(:salary => 0) 
      self.successful = true 
      flash[:info] = 'player fired' 
      self.successful = false 
      flash[:error] = 'Internal Error'

New Method process_action_link_action is doing all the magic and in addition should further simplify your action management.