I just deployed a rails app to Heroku and have found that there is a single javascript function. The function, officerCheck() lives in its own file officerCheck.js. And is called by an initialization file init.js with the line officerCheck.
The function is below; the first output to the log doesn't even show up
function officerCheck(){
console.log("officer check in");
var change=0;
$('#toggle-two-wrapper').on('change', function(){
if(change===0){
checking();
}else{
change=0;
}
});
function checking(){
var alert=0;
var existingRoles=[];
neededRoles=["President", "Secretary", "Treasurer"];
$("select.officer_role").each(function(i,e){
existingRoles[i]=$(e).val();
console.log("existing Roles "+existingRoles[i]);
});
$(neededRoles).each(function(i,e){
if($.inArray(e,existingRoles)==-1){
alert=1;
$('div#final-submission').prepend("<span class='warning' style='display:block'>"+e+" needed.</span>");
$("span.warning").delay(9000).slideUp("medium");
}
});
console.log("alert equals "+alert);
if(alert==1){
console.log("we're in");
change=1;
$('div.incorporation_submit #toggle-two').bootstrapToggle('off');
}
}
}
Here is a list of what I've investigated so far:
- All other javascript functions work (including those called by init.js)
- The function
officerCheckdoes indeed work on my localhost and heroku is up do date with that machine. - The function
officerCheckand its respective call is indeed loaded by the browser when I'm browsing the heroku-hosted site. (I can see both in my script tab in firebug). - The contents of the function still work if I cut and paste them into firebug. (Leading me to believe that heroku just doesn't like how I'm calling the function)
- Calling the function from firebug with
officerCheck();does NOT work. - However loading the function in its entirety into firebug and calling it with
officerCheck();DOES work.
I'm guessing that I'm pulling some sloppiness that Heroku just won't stand for. Any ideas thoughts or admonishments are welcome.
changedeclared? Maybe try another variable name and add thevardeclaration for starters.officerCheckwithout the parentheses, then you should get an output :function. If you don't, this means your function is not found and you should check your assets. Also, if you are running at localhost in development mode and in Heroku production mode, make sure you have compiled your assets AFTER having created the function.officerCheckwithout parentheses wasofficerCheck()Does that count? I have indeed been running in development mode so I'll check on that order of operations. Thanks for the help.checking(), but that should be a browser thing and it should work or not regardless where your app is hosted.... Does your browser provide any feedback as to why the function is not ran?