I'm trying to do something ONLY if a variable DOES exist (the variable's name is @filter), the problem is I can't seem to figure out how to get the code to work. I keep getting
undefined method `male_filter' for nil:NilClass
even when the first if should do the trick. Here's the actual code of the javascript:
$(document).ready(function(){
if(typeof <%=@filter%>!='undefined'){
if(typeof <%[email protected]_filter%>!='undefined'){
if(<%[email protected]_filter%>=='18'){
$('#18M').addClass('active');
}
else if(<%[email protected]_filter%>=='21'){
$('#21M').addClass('active');
}
else if(<%[email protected]_filter%>=='24'){
$('#24M').addClass('active');
}
}
}
}
I also tried adding a boolean in the controller called filterExists, and did the following:
var filterExists=<%=@filterExists%>;
if(filterExists==true){...}
But I still got the same error:
undefined method `male_filter' for nil:NilClass