Fellow Stranger
Fellow Stranger

Reputation: 34013

Only need simple_format when there are is new line \n

I have some strings that contain carriage return (new lines), and using the helper method simple_format works perfect for that.

Unfortunately though, now all strings get the wrapping tag and class defined with simple_format, and that creates unwanted styling for strings that don't contain carriage return.

Is there any way to get the benefits of simple_format only when needed?

Upvotes: 0

Views: 176

Answers (1)

Fellow Stranger
Fellow Stranger

Reputation: 34013

my_string.include?("\n") ? simple_format(my_string) : my_string

Upvotes: 3

Related Questions