RoR: ActiveScaffold: как сделать условие update_column условным? - PullRequest
0 голосов
/ 11 октября 2010

Схема:

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

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

Цель - скопировать action_types.description в actions.description, только если он еще не занят в пользовательском интерфейсе (!).

Что сделано:

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

В качестве альтернативы я могу принять, если у нас нет этой функциональности во время «обновления» только при «создании».Что является полумерой, но пока будет достаточно.

Есть идеи?

(Rails 2.3.4)

1 Ответ

0 голосов
/ 13 октября 2010

Проголосуйте и примите за них:

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

Вы можете скопировать метод javascript_for_update_column в свой вспомогательный файл и изменить :with на "Form.serialize(this.form)" (с *)1009 *).

В методе after_render_field вы можете использовать:

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

FYI: пустые поля появляются как nil s, а не пустые строки.

...