# RJS: pass javascript variables in ruby calls

**URL:** <https://www.ruby-forum.com/t/rjs-pass-javascript-variables-in-ruby-calls/162269>\
**Category:** Rails\
**Created:** [March 7, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/rjs-pass-javascript-variables-in-ruby-calls/162269 "2009-03-07T21:45:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![deadinplastic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@deadinplastic](https://www.ruby-forum.com/u/deadinplastic)\
**Post date:** [March 7, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/rjs-pass-javascript-variables-in-ruby-calls/162269/1 "2009-03-07T21:45:43Z")

</div>

Hey,

I have this link\_to\_function which takes an RJS block as follows:

page.insert\_html :bottom, :documents,  
:partial =\> “upload\_fields”,  
:locals =\> { :doc =\> Document.new, :index =\> ‘UNIQUE\_ID’ }

It adds a partial to a div. I need index to be a unique id, but can’t  
generate one.  
I have an actual javascript function next\_index() that will return the  
next index that works.  
Is there any way I can get the return value from that function passed  
as the index parameter on the insert\_html call? If not, is there any  
way I can get a unique id in there?

Thanks for any help!
