Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails how to make a Conditional CLASS

<%=f.text_area :content, :class => 'grow'

I want the class to be conditional to be either "grow" or "nogrow"

I tried

<%=f.text_area :content, :class => grow ? "comment_content grow" : "nogrow"

but that errors. any ideas?

like image 267
AnApprentice Avatar asked Dec 22 '22 19:12

AnApprentice


2 Answers

It's all about String Interpolation. Try This...

<%=f.text_area :content, :class => "#{grow ? 'comment_content grow' : 'nogrow'}" %>
like image 116
ChuckJHardy Avatar answered Jan 10 '23 10:01

ChuckJHardy


:class => grow ? "comment_content grow" : "nogrow" works just fine for me, you just need to end the line with %>. I suppose you could add some brackets - :class => (grow ? "comment_content grow" : "nogrow"), better for readability anyway.

like image 29
gunn Avatar answered Jan 10 '23 09:01

gunn