Idva Idva - 2 years ago 158
Ruby Question

Calling Coffeescript variables in Slim

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:

@square = (x) -> x * x

p square(3)

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

Answer Source

You can do it like so

   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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download