سؤال

If I want to insert a <br/> as part of the markup inside the label form helper, how do I do it?

Right now when I do this:

<%= f.label(:foo, "Foo <br/> Bar: ") %>

It outputs Foo <br/> Bar as the text of the label.

What I want is the label to have the line break between Foo and Bar. Like this:

Foo

Bar

هل كانت مفيدة؟

المحلول

The string needs to be marked as HTML safe so that Rails will not sanitize the output. Here is the concise way to write the label.

<%= f.label :foo, 'Foo <br /> Bar: '.html_safe %>

نصائح أخرى

Use the raw method

<%= f.label(:foo, raw("Foo <br/> Bar: ")) %>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top