0

Possible Duplicate:
How to access instance variables in CoffeeScript engine inside a Slim template

How can I use Ruby code in my coffee tags?

#{} is a slim construction to call Ruby code, but it doesn't work in coffee tag, because `#´ is used to begin a comment in CoffeeScript.

coffee:
     window.awesomeIcons.currentUser = #{raw current_user.to_json} #Doesn't work

What to do?

Community
  • 1
  • 1
just so
  • 1,088
  • 2
  • 11
  • 23

1 Answers1

2

To put it simply - it's not possible (at least not directly). Have a look at this issue on Slim's issue tracker. This is the relavant bit by @minad (one of Slim's devs):

It is not possible to implement this because coffee script is transformed at compile time. You could only embed normal javascript. To avoid confusion we didn't implement interpolation in the coffee filter.

I'd suggest using the gon gem to expose a JavaScript variable from your Rails controller than you can directly access in the Coffee filter later on.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117