Fields_for动态标签 [英] Fields_for dynamic label

查看:87
本文介绍了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.

推荐答案

好!这反映了我对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.

这篇关于Fields_for动态标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆