Dec3

ActiveScaffold summary fields

Closed

In one project I am the “gatekeeper” of a list of potential initiatives that the organization would like to explore as sources of revenue.

These initiatives are cross-regional in Asia, and best practice would call for the subject matter experts on each country to “own” and maintain the initiatives.

Thanks to the beauty of Rails, ActiveScaffold and other wealth of plug-ins available for Rails, in just 2 or 3 days of coding I was able to get the basics of a web application to handle this. Much better than a shared Excel Spreadsheet.

By the way, I tried using Sharepoint to maintain this list, and was underwhelmed. Anyway, recently added a summary field on the initiatives I track, to be able to show total (forecast) revenue and sales.  Followed the documentation on the ActiveScaffold website, and started receiving an error:

Showing vendor/plugins/active_scaffold/frontends/default/views/
_list_calculations.rhtml where line #12 raised:

undefined local variable or method `_erbout' for #<actionview ::Base:0xb518c850>

Extracted source (around line #12):

9:         override_formatter = "render_#{column.name}_#{column.calculate}"
10:         calculation = self.method(override_formatter).call(calculation) if respond_to? override_formatter
11:
12:         _erbout.concat calculation.to_s
13:         -%>
14:       < % else -%>
15:         &nbsp;

Trace of template inclusion: vendor/plugins/active_scaffold/frontends/
default/views/_list.rhtml, vendor/plugins/active_scaffold/frontends/
default/views/list.rhtml

The variable _erbout is the default output variable from an Erb object (see http://noobkit.com/show/ruby/ruby/standard-library/erb/new.html)

My proposed fix (I’ll send a patch to the ActiveScaffold devs) is to remove the _erbout reference and replace by

  < % if column.calculation? -%>
    < %
      calculation = column_calculation(column)

      override_formatter = "render_#{column.name}_#{column.calculate}"
      calculation = self.method(override_formatter).call(calculation) if respond_to? override_formatter
    -%>
    < %= calculation.to_s -%>
  < % else -%>
    &nbsp;
  < % end -%></actionview>

Feb8

Complex validation in Rails through plugins

Tagged with: .
Closed

I’m writing a portfolio management application in Rails where complex validations are required between fields of instances. The MVC paradigm of Rails is very good to encapsulate all the business logic of the application in a very readable way.

I found an article here describing how to add validations to a model through plugins, making them reusable and semantically clear.

Even if you don’t have in mind reusability, which was my case, the added clarity if this method is worth the additional work of creating a plugin.

Complete information on how to write plugins can be found here