RoR:ActiveScaffold:如何使 update_column fetaure 有条件?

发布于 2024-09-26 20:02:59 字数 1228 浏览 10 评论 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)

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2024-10-03 20:02:59

投票并接受他们:

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 nils, not empty strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文