为什么 Rails 不显示以句点结尾的字符串 [英] Why is Rails not displaying strings that end in a period

查看:42
本文介绍了为什么 Rails 不显示以句点结尾的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将此字符串保存到地址字段:

If I save this string to an address field:

11060 Westmoor 博士

11060 Westmoor Dr.

它不会显示在 UI 中.

It doesn't display in the UI.

但如果保存时最后没有句号,

But if it saved without the period at the end,

11060 Westmoor 博士

11060 Westmoor Dr

然后是在 UI 中显示.

Then is does display in the UI.

为什么句号导致字符串不显示?

Why does the period cause the string not to display?

我是这样显示的:

<%= f.label "#{user_event.address1}, ", class: 'info_label' %>

谢谢!

推荐答案

我不知道您为什么以这种方式使用标签.标签应用作字段名称.因此,与其输出某人的地址字符串,不如像这样使用它:

I'm not sure why you're using a label in this manner. The label should be used as a field name. So, rather than output the string of someone's address, you should use it like:

<%= f.label :address_line_1 %>
<%= f.text_field_tag :address_line_1 %>

Rails 删除了这里的标点符号,因为你不能有."作为方法名

Rails is removing punctuation here because you can't have "." as method names

这篇关于为什么 Rails 不显示以句点结尾的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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