views:

32

answers:

2

Hi,

i have an .js.rjs file, that must be used in many places.

How can i reuse it ?

For example, in my .js.rjs file i need something like this:

page << ( render "widely_used_stuff" )

where "widely_used_stuff" is a widely_used_stuff.js.rjs file, that contains the code, used in many places.

Also, i need to pass the variables to widely_used_stuff.js.rjs, like in this way:

page << ( render "widely_used_stuff", :locals => {:custom_script => my_script} )   

Update 1

I have tried following ways from .js.rjs file:

render "widely_used_stuff"

Rails complains on it, because it requires this "partial" to be "erb" partial

Following way:

render :file => "controller/widely_used_stuff.js.rjs"

Rails don't complains, but "widely_used_stuff.js.rjs" is not inserted to .js.rjs file, that called render. I have checked the XHR response.

I think, the problem is in the caller .js.rjs file, because it is not a erb...

+1  A: 

Hi have you tried render "controller/widely_used_stuff.js.rjs" ?

Bohdan Pohorilets
yes. See Update 1
AntonAL
A: 
render :partial => 'view_directory/widely_used_stuff.js.rjs'
Matt Briggs
No, it not works. I tried it
AntonAL