Formtastic 如何决定在“select”选项中使用哪个表列来表示行?

发布于 2024-12-10 01:05:29 字数 260 浏览 4 评论 0原文

当您执行以下操作时:

form.input :users

并且属性 #users 表示 has_many 关系,然后 Formtastic 会生成一个包含用户 #id 和 #name 的 select 字段,但是...

如何Formtastic 是否决定必须使用 #name 列?

为什么不#email 或#login?是否可以指定它而无需手动创建集合?

When you do the following:

form.input :users

And the attribute #users represents a has_many relationship, then Formtastic generates a select field with the user #id and #name, but...

How do Formtastic decides that the #name column is what has to be used?

Why not #email, or #login? Is possible to specify it without having to create the collection manually?

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

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

发布评论

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

评论(1

闻呓 2024-12-17 01:05:29

好吧,我找到了答案, :select 标签的源注释如下:

Formtastic 呈现 value 属性和内容的方式
每个 标记都可以通过 :member_label 进行自定义,
:member_value 选项。如果没有提供,我们会退回到以下列表
尝试每个对象的方法,例如 :to_label:name
:to_s,在配置中定义
collection_label_methodscollection_value_methods

https://github.com/justinfrench/formtastic/blob /master/lib/formtastic/inputs/select_input.rb

Well I found my answer, the source comments for the :select tag says the following:

The way on which Formtastic renders the value attribute and content
of each <option> tag is customisable through the :member_label and
:member_value options. When not provided, we fall back to a list of
methods to try on each object such as :to_label, :name and
:to_s, which are defined in the configurations
collection_label_methods and collection_value_methods.

https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb

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