How do I escape the ERB tag in ERB

Ruby on-RailsUnit TestingErbFixture

Ruby on-Rails Problem Overview


I have a simple fixture.yml file:

label:
    body: "<%= variable %>"

The issue is that the ERB code is parsed as part of loading the fixture, whereas I actually want the body to be literally "<%= variable %>" (un-interpolated).

How do I escape the ERB tag?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Add a second % to the opening tag:

label:
    body: "<%%= variable %>"

The <%% sequence is valid ERB, rendered as a literal <%.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDanielView Question on Stackoverflow
Solution 1 - Ruby on-RailsmolfView Answer on Stackoverflow