为了在某些页面上包含一段我只需要的 javascript,我把
= javascript_tag do
= render "inserts_js_enhanced_element.js.erb"
在我的haml
档案中。现在我在测试中收到警告:
DEPRECATION WARNING: Passing a template handler in the template name is
deprecated. You can simply remove the handler name or pass render
:handlers => [:erb] instead.`
但是,当我将线路更改为
= render "inserts_js_enhanced_element.js", :handlers => [:erb]
无论如何,我收到一个新警告,说
DEPRECATION WARNING: Passing the format in the template name is
deprecated. Please pass render with :formats => [:js] instead.
如果我确实将其更改为
= render "inserts_js_enhanced_element", :handlers => [:erb], :formats => [:js]
它给了我错误
ActionView::Template::Error:
Missing partial application/inserts_js_enhanced_element with {:handlers=>[:haml, :builder, :erb, :coffee], :locale=>[:de], :formats=>[:html]}.
现在格式似乎没有改变,:js
而且处理程序不仅是:erb
. 我应该如何正确输入 JS-ERB?
更新:
js.erb 文件的格式为
<% session_val = determine_session_val_from_config %>
jQuery(document).ready(function() {
//JS Code
}