【问题标题】:string with full stop in it not properly outputted in html带有句号的字符串未在 html 中正确输出
【发布时间】:2012-03-07 10:47:02
【问题描述】:

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

<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? 

【问题讨论】:

    标签: html ruby-on-rails ruby-on-rails-3 postgresql


    【解决方案1】:

    不确定消失的文本部分,但标签助手将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 %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 2019-08-26
      • 2021-10-13
      • 1970-01-01
      相关资源
      最近更新 更多