gpt4 book ai didi

html - 带句号的字符串未在 html 中正确输出

转载 作者:行者123 更新时间:2023-11-29 13:36:29 25 4
gpt4 key购买 nike

我的 Ruby on Rails 项目中有一个 Question 模型,它使用 Postgresql 数据库,它有一个名为 question 的字符串数据类型。 (原来嘿!) 当我输入一些带有句号 (.) 的数据时,它没有在我的 html/erb View 文件中正确打印/输出,句号之前的所有内容都丢失了!

<div class="field">
<%= f.label question.question %><br />
....

根据 psql 控制台的以下输出,它正确地存储在我的数据库中

select question from questions where "id"=1;
question
----------------------------------
What is 2+3. What is the answer?
(1 row)

有谁知道这里发生了什么(以及解决方法)?我已经尝试过诸如 .html_safe 和 .to_s 之类的东西,但都无济于事。

编辑:关于 html 输出的另一件困扰我的事情是它去掉了我所有的大写字母。什么鬼?!

所以示例的 html 输出将在下面...

what is the answer? 

最佳答案

不确定消失的文本部分,但标签助手将 humanize 方法应用于自动生成的标签文本(即,如果没有传入明确的标签文本)。在控制台中它看起来像这样:

ruby-1.9.2-p290 :006 > helper.label_tag "All Caps String"
=> "<label for=\"All_Caps_String\">All caps string</label>"

作为解决方法,请尝试提供明确的标签值:

ruby-1.9.2-p290 :007 > helper.label_tag "All Caps String", "All Caps String"
=> "<label for=\"All_Caps_String\">All Caps String</label>

那么试试这个:

<%= f.label question.question, question.question %>

关于html - 带句号的字符串未在 html 中正确输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9599989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com