是否有可能有一个js.erb部分在轨3.0?有可能、有一个、部分、js

2023-09-10 16:52:45 作者:老鼠扛刀满街找猫

如果有可能,我怎么能由另一个js.erb文件运行呢?

If it is possible, how can I run it from another js.erb-file?

试图让事情干!

编辑: 说明:我在寻找/ index.js.erb的一个js.erb程序。我想用在位置/ index.js.erb的相同的程序。因此,我想,如果我可以做一个局部containg js.erb code,这样我就不必从第一index.js.erb的文件复制程序到另一个。

Explanation: I have a js.erb routine in search/index.js.erb. I want to use the same routine in location/index.js.erb. Therefore I wondered if I could make a partial containg js.erb code, so that I don't have to copy the routine from the first index.js.erb file to the other one.

推荐答案

YES。你可以有一个共同的部分(比如文件夹中:应用程序/视图/谐音),并用 * js.erb 文件中像这样<%=渲染:部分=> path_to_partial,:当地人=> {....}%GT;

YES. you can have a common partial (say in a folder: app/views/partials) and use that partial's path inside your *.js.erb file like this <%= render :partial => path_to_partial, :locals => { ....} %>

如果你想提取的HTML串出的部分,你也可以用

If you want to extract the html string out of a partial you can also use

render_to_string :partial => path_to_partial