RoR:ActiveScaffold:如何使 update_column fetaure 有条件?
架构:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
投票并接受他们:
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
code>s,不是空字符串。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
nil
s, not empty strings.