You are correct in that it is not a good idea to duplicate your code. As for your question of where to put the javascript files, it doesn't really matter (though typically, for reasons beyond the scope of your question, they reside in app/assets/javascripts
).
The important thing is that the javascript functions you're calling from new.js.haml
have actually been defined, which means the javascript file must be loaded. This can be done by including the javascript file in the of your layout, like this:
<%= javascript_include_tag "admin/admin" %>
Define functions in your main javascript file:
// admin.js
var testFunc = function() {
console.log('this is a test!')
};
then call the function in your new.js file:
// new.js
testFunc();
No need to redefine your functions or variables.