How do I escape the ERB tag in ERB

2019-01-13 03:31发布

问题:

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?

回答1:

Add a second % to the opening tag:

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

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