简体   繁体   English

在CSS类中使用条件语句(Rails / View)

[英]Using Conditional Statement within a css class (Rails/View)

In Rails/Haml 在Rails / Haml中

I know this works 我知道这有用

%i.class{:class => (name ? "arrow-up" : "arrow-down")} 

I also know that I can make a helper function 我也知道我可以做一个助手功能

%i.class{:class => (getArrowClass name)}

def getArrowClass value
if value == 1
   return 'arrow-up'
elsif value == 0
  return 'arrow-down'
else
  return ''
end
end #getArrowClass

For some reason, whenever I do the helper way it messes up my view (tables don't stick to their places), so now my question is how can I do the if elsif else in the class using the first method. 出于某种原因,每当我使用辅助方法时,它都会弄乱我的视图(表不会停留在它们的位置),所以现在我的问题是,如何使用第一种方法在类中执行ifif elsif else。

something like that 这样的东西

%i.class{:class => (if name then "arrow-up" elsif "arrow-down" else "")} 

请尝试

%i.class{:class => ((name == 1) ? "classup" : (name == 0) ? "classdown" : "")}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM