4

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...

AntonAL
  • 16,692
  • 21
  • 80
  • 114

3 Answers3

2

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

Bohdan
  • 8,298
  • 6
  • 41
  • 51
2
page << render(:file => "common/index.js.rjs")

i hope could help .

andrea
  • 3,515
  • 2
  • 22
  • 14
1
render :partial => 'view_directory/widely_used_stuff.js.rjs'
Matt Briggs
  • 41,224
  • 16
  • 95
  • 126