Search code examples
ruby-on-railshaml

Rails: Tilde usage in HAML


I just stumbled across this line in a HAML/Rails form:

~ f.input :content, label: false

What does the tilde do?


Solution

  • Whitespace Preservation: ~:

    ~ works just like =, except that it runs Haml::Helpers#find_and_preserve on its input. For example,

    ~ "Foo\n<pre>Bar\nBaz</pre>"

    is the same as:

    = find_and_preserve("Foo\n<pre>Bar\nBaz</pre>")

    and is compiled to:

    Foo <pre>Bar&#x000A;Baz</pre>