10

I have this div

<div class='notice'>

And I want the result to be

<div class="notice error">

And Is there a way to add a class in my erb? I tried

<div class="notice #{new_class}">

But that doesn't escape into ruby code when it renders...

and ideas?

2 Answers 2

32

It's with <%= %>

<div class="notice <%= new_class %>">
Sign up to request clarification or add additional context in comments.

Comments

15

I believe

<div class="notice <%= h new_class -%>">

works, albeit a little ugly. You could also do the prettier, but more longwinded

<%= content_tag(:div, "Your content here", :class => "notice #{new_class}") %>

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.