admin管理员组文章数量:1026989
I've got a getJSON
script that should respond if a Ruby value is not nil
, but I'm not sure how to check for if not (ruby's version of) nil
through javascript. So far it looks like this:
$.getJSON("<%= xhr_document_path(document) %>", function(d) {
if (d.ok) {
$('#modal_<%= document.id %>').modal('show');
clearInterval(doc_modal_<%= document.id %>);
} else if (d.error != '') {
window.location.href = "<%= error_document_path(document) %>";
}
});
But the else if
condition is tripped when the value is nil. How do I check for not nil
here?
I've got a getJSON
script that should respond if a Ruby value is not nil
, but I'm not sure how to check for if not (ruby's version of) nil
through javascript. So far it looks like this:
$.getJSON("<%= xhr_document_path(document) %>", function(d) {
if (d.ok) {
$('#modal_<%= document.id %>').modal('show');
clearInterval(doc_modal_<%= document.id %>);
} else if (d.error != '') {
window.location.href = "<%= error_document_path(document) %>";
}
});
But the else if
condition is tripped when the value is nil. How do I check for not nil
here?
1 Answer
Reset to default 7If d
was converted from Ruby to JavaScript through JSON, then the Ruby nil
would be converted to JavaScript null
.
I've got a getJSON
script that should respond if a Ruby value is not nil
, but I'm not sure how to check for if not (ruby's version of) nil
through javascript. So far it looks like this:
$.getJSON("<%= xhr_document_path(document) %>", function(d) {
if (d.ok) {
$('#modal_<%= document.id %>').modal('show');
clearInterval(doc_modal_<%= document.id %>);
} else if (d.error != '') {
window.location.href = "<%= error_document_path(document) %>";
}
});
But the else if
condition is tripped when the value is nil. How do I check for not nil
here?
I've got a getJSON
script that should respond if a Ruby value is not nil
, but I'm not sure how to check for if not (ruby's version of) nil
through javascript. So far it looks like this:
$.getJSON("<%= xhr_document_path(document) %>", function(d) {
if (d.ok) {
$('#modal_<%= document.id %>').modal('show');
clearInterval(doc_modal_<%= document.id %>);
} else if (d.error != '') {
window.location.href = "<%= error_document_path(document) %>";
}
});
But the else if
condition is tripped when the value is nil. How do I check for not nil
here?
1 Answer
Reset to default 7If d
was converted from Ruby to JavaScript through JSON, then the Ruby nil
would be converted to JavaScript null
.
本文标签: Ruby check for nil in javascriptStack Overflow
版权声明:本文标题:Ruby: check for nil in javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745660362a2161851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论