ruby on rails 3.2

Is there a way to write a case statement in Slim for the following example. I made some changes for the StackOverflow question: How to write a switch statement in Ruby

case a
when 1..5
  = "It's between 1 and 5"
when 6
  = "It's 6"
when String
  = "You passed a string"
else
  = "You gave me #{a} -- I have no idea what to do with that."
end

I tried the following but generates an error.

= case @taxon.name
  = when "Wedding Cakes"
    div.taxon-descripiton Wedding Cake Description

This is what I am told

... syntax error, unexpected tIVAR, expecting keyword_when
; @output_buffer.safe_concat(("<when>"Weddin...

= is used when you want to render something, when you want to call some ruby logic without rendering anything in a view you should use - :

   - case @taxon.name    
     - when "Wedding Cakes"    
       div.taxon-descripiton Wedding Cake Description

I am not sure this will solve your problem though, have you considered moving this logic to a decorator anyway?

链接地址: http://www.djcxy.com/p/25640.html

上一篇: C#将引号放在引号内?

下一篇: 红宝石在轨道上3.2