RoR:记录的自定义更新
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_at
和 created_by
由 before_create_save()
填充。因此用户实际填写的唯一字段是 question_text
。
下一步是创建一个“响应”操作(而不是“编辑”),该操作与 :update
非常相似,但有一些差异。该操作的形式将排除所有字段,除了 response_text
之外,before_respond_save()
会填充 lined_by
和 lined_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我放弃了以这种方式解决问题。因为我相信当前的环境不支持我的方法。相反,我继续写表格。请参阅 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