1

How can I set the class of an element in a Rails view's haml?

For example, suppose I want to set the CSS class of a %td% element that's written like this to the "red" class:

%td= book.author

How would this be written?

1 Answer 1

3

That looks like Haml.

You can use either %td.red= book.author or %td{:class => "red"}= book.author.

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

2 Comments

Yes, I'm a total RoR newbie taking a class; I assumed haml is a given?
Not necessarily! Rails can use many templating languages, include ERB (the default), Haml, Slim, and a number of others. Haml is definitely popular though. :)

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.