0

スキーマ:

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

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

目標は、action_types.description を actions.description にコピーすることです (UI でまだ使用されていない場合のみ) (!)。

行われること:

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)"(から"'value=' + this.value")に変更できます。

メソッドでは、after_render_field次を使用できます。

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

参考:空のフィールドはnil、空の文字列ではなく、sとして表示されます。

于 2010-10-13T13:30:30.797 に答える