How do I escape the ERB tag in ERB
Asked Answered
A

1

85

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?

Aftmost answered 23/2, 2010 at 22:58 Comment(0)
S
137

Add a second % to the opening tag:

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

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

Sweven answered 23/2, 2010 at 23:0 Comment(2)
ah ha! I was doubling both of them! TYAftmost
This would be what you would use to print out an erb-style JST (ie underscore) within a a rails erb file.Spoony

© 2022 - 2024 — McMap. All rights reserved.