how to pass ruby instance variable as params to js function in a rjs page

260 views Asked by At

I have an instance variable @foo in my create controller action and I am rendering create.rjs template. In the RJS template I need to call a js function (with page.call) and pass @foo as params. How is it possible..

2

There are 2 answers

0
Keith Norman On BEST ANSWER

It's been years since i've used RJS, but this might work:

page.call "your_function(#{ escape_javascript(@some_instance_var) })"
0
Chris Vo On

Check out the gem gon. I am using it to pass rails variables to my javascript code.