Ruby on Rails - 在用户单击创建操作时连接保存到数据库的字符串
已经很晚了,我可能应该睡一觉了。很简单,
我的表单中有 3 个字段供用户填写。一旦他们单击“创建”按钮,这些记录就会保存到数据库中。简单的。
然而,我希望这三个字段的数据同时连接在一起,没什么花哨的......并与其他记录同时插入到数据库中。这应该在用户创建后反映在显示页面上。
所以我需要一个操作来连接 3 个数据库列,假设列名是名字、姓氏和出生日期。表名 PeopleDetails
我尝试使用模型中内置的 after_create、before_save 构建模型,但什么也没有。建议。我想我会在睡一觉后回来重新审视这个
Its late and I probably should sleep on this. Easy one
I have 3 fields in a form which a user fills in. Once they click the create button these records are saved to the database. Simple.
However I want the data from these three fields at the same time to be concatenated together, nothing fancy..and inserted to the database at the same time as the other records. This should reflect back to the user on the show page after they create.
So I need an action to concatenate 3 db columns lets say column names are firstname, surname and DOB. table name PeopleDetails
I have tried building the model using after_create, before_save, built into the model, but nada. suggestions. I think I will come back and revisit this after some sleep
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有一个名为
full_name
的列(模型属性),那么您可以通过以下方式将所有内容组合到模型创建/保存中:Assuming you have a column (model attribute) called
full_name
than you can combine all together on a model create/save via: