views:

36

answers:

1

Schema:

action_types
------------
id
name
description

actions
-------
id
action_type_id
date
description

The goal is to copy action_types.description to actions.description only if it is not occupied yet on the UI (!).

What is done:

class ActionsController < ApplicationController
    active_scaffold :action do |c|
        c.columns = [ \
            , :date \
            , :action_type \
            , :description \
        ]
        c.columns[:action_type].form_ui = :select
        c.columns[:action_type].options[:update_column] = :description
        c.columns[:description].form_ui = :textarea
        c.columns[:description].options = { :cols => 40, :rows => 5}
    end

protected

    def after_render_field(record, column)
        # record: almost empty, only "action_type" is filled.
        # column: column.name == "action_type"
        # @params[]: id: id for the record
        # But no data on UI state. So if the user wrote some lines into the
        # description then it will be lost. No possibility
        # to express "do nothing!"
    end

    #...
end

Alternatively I can accept if we do not have this functionality during "update" only on "create". Which is a half measure, but will be enough for now.

Any ideas?

(Rails 2.3.4)

A: 

Up-vote and accept for them:

http://markmail.org/message/cfbhmeyfjw3bjisp#query:+page:1+mid:vnnrbzdj7cywlvgm+state:results

You can copy javascript_for_update_column method into your helper file, and change :with to "Form.serialize(this.form)" (from "'value=' + this.value").

In after_render_field method you can use:

update_record_from_params(record, active_scaffold_config.update.columns, params[:record])

FYI: Empty fields are coming as nils, not empty strings.

Notinlist