Ruby: check for nil in javascript - Stack Overflow

I've got a getJSON script that should respond if a Ruby value is not nil, but I'm not sure ho

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?

Share Improve this question edited Apr 1, 2014 at 7:42 t56k asked Apr 1, 2014 at 7:36 t56kt56k 7,03110 gold badges58 silver badges121 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

If d was converted from Ruby to JavaScript through JSON, then the Ruby nil would be converted to JavaScript null.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745660364a4638797.html

相关推荐

  • Ruby: check for nil in javascript - Stack Overflow

    I've got a getJSON script that should respond if a Ruby value is not nil, but I'm not sure ho

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信