ruby-on-rails - Rails collection_select 不同的选定属性
问题描述
我有collection_select
来自其他模型的选项,我需要在下拉列表和选定值中显示不同的属性。即我需要在下拉列表中显示,object.title
但选择的值应该显示object.code
。我有一个代码:
f.collection_select :some_attribute_id, Country.all, :id, :title
当前在下拉列表中显示值和显示选定值是相同的属性。我试图做类似的事情
f.collection_select :some_attribute_id, Country.all, :id, :title, { prompt: @object.country.code }
或selected: @object.country.code
但不成功
解决方案
推荐阅读
- swift - SwiftUI 将值从几何阅读器传递给函数
- perl - Perl FileSelect:设置窗口位置
- sql - 将子字符串数字从 nvarchar 转换为数字
- typescript - ESLint 不报告 TypeScript 编译器类型检查错误
- reactjs - 用 Jest/Enzyme 测试延迟的自定义 React 钩子?
- javascript - 如何在 Discord 消息中找到单词?
- context-free-grammar - 匹配 Lark 中的子串
- python - ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败(运行名为 ADEL 小麦的包时出错——初学者)
- excel - Excel 中的分页符和合并单元格样式
- kubernetes - kube apiserver 如何与 kubelet 和 kube-proxy 通信?