架构:
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)