简体   繁体   中英

Rails json return with jbuilder html tags

On my controller I return json with index.json.jbuilder .

On the controller part, I have an array which stores the extras as;

..
@ti << ('&bull; ' + e.name + ': ' + price)
..

Then in the jbuilder part I have;

..
json.obligatory_body @ti.join("<br>")
..

I am trying to show these elements with a bullet with line breaks inside bootstrap popover.

Inside the popover this is how it looks like;

<a tabindex="0" class="pull-right color-red " role="button" data-toggle="popover" data-container="body" data-trigger="focus" data-placement="left" title="" data-content="• Fuel: 95 €<br>• Service: 100 € " data-original-title="">Details <i class="fa fa-info-circle" aria-hidden="true"></i></a>

Here data-content shows correctly but on the screen I see <br> tag as well instead of the line break.

Rails escapes the html tags by default. Try the following:

json.obligatory_body @ti.join("<br>").html_safe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM