Calling Coffeescript variables in Slim

1.1k views Asked by At

Im trying to declare a coffescript function and call it later in the code. I'm pretty new to this, and can't seem to find anything on it.

Here is the code im working on, as you can see I try to call the square function:

coffee:
  @square = (x) -> x * x

p square(3)

Here i want to get a p-tag containing "9"

1

There are 1 answers

0
MightyKho On BEST ANSWER

You can do it like so

p
 coffee:
   document.write @square(3) 

But !!NEVER EVER!! write such horrible things. In ROR Slim templates are for ruby only. And please don't define any methods there.