Include Directly
If you want the javascript included directly into the haml, you can use :javascript
:javascript
$(function() { alert("js inside haml"); }
You can put this into a partial and then just render the partial to keep your views clean.
Reference It
If you want to just reference javascript and have the browser pull it in, you should use javascript_include_tag
like always. Here, you'll need to make the javascript file a manifest, instead of requiring it into the application.js
manifest. Remember to add the manifest to config.assets.precompile
in your application.rb, according to http://guides.rubyonrails.org/asset_pipeline.html
(in your haml):
= javascript_include_tag 'somefile'
(in config/application.rb):
config.assets.precompile += ['somefile.js']