# Rails code in a Javascript function

**URL:** <https://www.ruby-forum.com/t/rails-code-in-a-javascript-function/121966>\
**Category:** Rails\
**Created:** [December 3, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/rails-code-in-a-javascript-function/121966 "2007-12-03T14:17:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![serkan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@serkan](https://www.ruby-forum.com/u/serkan)\
**Post date:** [December 3, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/rails-code-in-a-javascript-function/121966/1 "2007-12-03T14:17:17Z")

</div>

Hi guys!

In Rails, can you stick Rails code in a javascript function? An example,  
this code from the Geokit plugin on a view page which doesnt work for  
me:

Any help would be appreciated!

cheers!

---

<div class="post-metadata">

**Author:** ![serkan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@serkan](https://www.ruby-forum.com/u/serkan)\
**Post date:** [December 3, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/rails-code-in-a-javascript-function/121966/2 "2007-12-03T14:38:16Z")

</div>

you can put everything in a textfile with erb  
\<% … %\> will be executed  
\<%= … %\> will be executed and the return value inserted in the file

so the above code looks fine and you should give us some details what  
‘does not work’ for you. get an error message? nothing happens at all?  
the erb tags are inserted ‘as is’ in the output (check source code in  
browser)?
