Rails how to make a conditional class

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

I want the class to be conditional, to be either "growing" or "narrow"

I tried

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

but these are mistakes. any ideas?

+4
source share
2 answers

:class => grow ? "comment_content grow" : "nogrow" :class => grow ? "comment_content grow" : "nogrow" works 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.

+5
source

All About String Interpolation. Try it...

 <%=f.text_area :content, :class => "#{grow ? 'comment_content grow' : 'nogrow'}" %> 
+6
source

Source: https://habr.com/ru/post/1335699/


All Articles