Fields_for 动态标签
我有动态表单,它有一组值。我创建了一个包含我显示的文本字段的部分。在每个文本旁边,我想显示一个包含文本标题的标签。例如,名字和姓氏以前是未知的。我该如何去做呢? 看来我无法直接访问属性。但是当我使用标签字段时,标签中的变量名称显示而不是实际值。
I have dynamic form which has a set of values. I created a partial which contains text fields which I display. Next to each of them I would like to display a label containing the title of the text. For instance First Name, and Last Name would not be known previously. How do I go about doing that?
It seems that I cannot access the attributes directly. But when I use the label field, the variable name in the label is displayed not the actual value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出色地!这反映了我对 Rails 的陌生程度。您可以使用
f.object.{attr_name}
来完成此操作,并且效果很好。Well! This was a reflection of how new I am to rails. You can do this by using
f.object.{attr_name}
and that worked.f.object.{attr_name}
对我不起作用,但f.object[:attr_name]
对我有用。f.object.{attr_name}
didn't work for me, butf.object[:attr_name]
did.怎么样:
这将是 Ruby 方式。
What about:
That would be the Rubyish way.