RoR:记录的自定义更新

发布于 2024-09-14 18:19:58 字数 950 浏览 1 评论 0原文

questions
---------
id
topic_id
created_by
created_at
question_text
closed_by
closed_at
response_text

它出现在 topics 表下的嵌套表中。

我可以轻松创建问题,只需从config.create.columns 中排除:created_by、created_at、close_by、close_at、response_text。 (created_atcreated_bybefore_create_save() 填充。因此用户实际填写的唯一字段是 question_text

下一步是创建一个“响应”操作(而不是“编辑”),该操作与 :update 非常相似,但有一些差异。该操作的形式将排除所有字段,除了 response_text 之外,before_respond_save() 会填充 lined_bylined_at

有什么方法可以做到吗 ?这无需手动创建自定义视图(.erb.rhtml)?

(简而言之:有没有办法稍微逃避“CRUD”,但不是手工做所有事情?)

编辑:排除示例

active_scaffold do |config|
  # ...
  config.create.columns.exclude [:created_by, :created_at, :closed_by, :closed_at, :response_text]
  # ...
end
questions
---------
id
topic_id
created_by
created_at
question_text
closed_by
closed_at
response_text

It appears in a nested table under the topics table.

I can easily create a question, I just have to exclude :created_by, created_at, closed_by, closed_at, response_text from config.create.columns. (created_at and created_by is filled with before_create_save(). So the only field the user actually fills is question_text.

The next step would be to create a "Respond" action (instead of "Edit") which would be very similar to an :update with a few differences. The form of this action would exclude all fields, except response_text. The before_respond_save() would do the filling of closed_by and closed_at.

Is there any way of doing this without creating custom views (.erb, .rhtml) with hand?

(In short: Is there any way to escape from "CRUD" a little-bit, but not doing everything by hand?)

EDIT: Example for exclude

active_scaffold do |config|
  # ...
  config.create.columns.exclude [:created_by, :created_at, :closed_by, :closed_at, :response_text]
  # ...
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

爱给你人给你 2024-09-21 18:19:58

我放弃了以这种方式解决问题。因为我相信当前的环境不支持我的方法。相反,我继续写表格。请参阅 RoR:如何处理自定义嵌套表单的提交

I gave up on solving the problem this way. As I believe the current environment does not support my approach. Instead, I went on with writing forms. See RoR: How to handle custom nested form's submit

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