0

I have a Rails Model called Events which has as field/attribute called :description.

I migrated it under the type t.text rather than t.string since I was going to be displaying a large amount of data.

So.... Now I'm at the point where I would like to display <%= @event.description %> in a neat way and would like to break up some of the sentences rather than one large block of information.

I was hoping I could insert <p> or other html codes to help with how the text is displayed.

The problem is inserting <p> into the field only prints <p> and the not desired action of the html command.

How can I add html styling to the text attribute?

2 Answers 2

8

You can use <%=raw @event.description %> to echo unescaped content. Be aware that this is a potential XSS security hole, if users can ever affect that content. I highly recommend using the sanitize helper to strip out any unwelcome markup before you write it out.

Sign up to request clarification or add additional context in comments.

Comments

0

It strictly depends on how you print it. In particular, if you print with calling h function (<%= h my_text =>), output will be sanitized and html escaped.

It may also depend on your rails version: I've head in Rails 3 html is escaped by default, even if you don't use h.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.