0

架构:

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

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

目标是仅当 UI 上尚未占用 action_types.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

或者,如果我们在“更新”期间仅在“创建”时没有此功能,我可以接受。这是一个一半的措施,但现在就足够了。

有任何想法吗?

(导轨 2.3.4)

4

1 回答 1

0

为他们投票并接受:

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

您可以将方法复制javascript_for_update_column到您的帮助文件中,然后更改:with"Form.serialize(this.form)"(from "'value=' + this.value")。

after_render_field方法中,您可以使用:

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

仅供参考:空字段以nils 形式出现,而不是空字符串。

于 2010-10-13T13:30:30.797 回答