I have a .js.rjs file that should 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 "wide_used_stuff" is the file wide_used_stuff.js.rjs containing the code used in many places.
In addition, I need to pass variables to wide_used_stuff.js.rjs, for example, as follows:
page << ( render "widely_used_stuff", :locals => {:custom_script => my_script} )
Update 1
I tried the following methods from a .js.rjs file:
render "widely_used_stuff"
The rails complain about it because it requires this "partial" to be partial "erb"
In the following way:
render :file => "controller/widely_used_stuff.js.rjs"
Rails do not complain, but "wide_used_stuff.js.rjs" is not inserted into the .js.rjs file called render. I checked the XHR answer.
I think the problem is in the calling .js.rjs file, because it is not erb ...
source share