rails helper - 我怎样才能得到一个帮手给我一个`<br/>`(或其他标记) [英] rails helper - how can I get a helper to give me a `<br/>` (or other markup)

查看:27
本文介绍了rails helper - 我怎样才能得到一个帮手给我一个`<br/>`(或其他标记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的助手是这样工作的:

def some_help(in_string)in_string + "和更多"结尾

但我希望它在输出之前对
进行处理,并且我不断收到 <br > 字面上的字符本身,即不是中断,而是我想要的是 <br > 这就是问题所在.

所以

def some_help(in_string)<br/>"+ in_string + "和更多"结尾

工作不正常.

解决方案

使用 tag(:br) 而不是 "<br/>".>

content_tag(:br) 创建打开和关闭 br 标签,使用 rawhtml_safe 只是丑陋(更不用说危险了).

My helper works like this:

def some_help(in_string)
  in_string + " and more"
end

But I want it do to a
before the output and I keep getting the < br > characters themselves literally, i.e. not a break but what I want is a < br > that is the problem.

so

def some_help(in_string)
  "<br/>" + in_string + " and more"
end

doesn't work right.

解决方案

Use tag(:br) instead of "<br/>".

content_tag(:br) creates opening and closing br tags and using raw or html_safe is just ugly (not to mention dangerous).

这篇关于rails helper - 我怎样才能得到一个帮手给我一个`&lt;br/&gt;`(或其他标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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