开发者

rails how to make a Conditional CLASS

开发者 https://www.devze.com 2023-02-04 05:40 出处:网络
<%=f.text_area :content, :class => \'grow\' I want the class to be conditional to be either \"grow\" or \"nogrow\"
<%=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 error开发者_如何转开发s. any ideas?


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

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


: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.

0

精彩评论

暂无评论...
验证码 换一张
取 消