简体   繁体   English

基于HAML的视图的JavaScript模板

[英]JavaScript template for a HAML based view

I have a Ruby on Rails application that is using HAML based template views. 我有一个使用基于HAML的模板视图的Ruby on Rails应用程序。 I need to drop a simple: 我需要删除一个简单的:

alert('Hello World'); JavaScript excerpt template that I can build off that loads for the page. 我可以为页面加载的JavaScript摘录模板。

If my controller's name is Foo and my actions name is bar , I put a bar.js.haml into app/views/foo/ and it doesn't seem to load any of that JS when I load the page up. 如果我的控制器名称为Foo且动作名称为bar ,则将bar.js.haml放入app/views/foo/并且在加载页面时似乎未加载任何该JS。

What can I do to debug this and get JavaScript embedded into my haml views? 我该怎么做才能调试并将JavaScript嵌入到haml视图中?

Right, it's not going to auto include or auto reference another script for you. 是的,它不会为您自动包含或自动引用另一个脚本。 If you want to add javascript to the page using HAML: 如果要使用HAML将javascript添加到页面:

:javascript
  alert('Hellooooooooooo');

Update with way to link to javascript file named "bar.js" in app/assets/javascripts 更新链接到app / assets / javascripts中名为“ bar.js”的javascript文件的方式

= javascript_include_tag "bar"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM