mardi 25 août 2015

Get image from sqlite db and display on page with JavaScript

I am trying to query my sqlite table to get an image and display it on the page. This is the code I am working with. The weird thing is [0] to [4] doesn't show anything, and [5] and higher returns undefined. My table only has 5 items in it so it looks like the query is working, but it still does not load the items onto the page.

<script type="text/javascript">

    $(document).ready(function() {

        var image = <%= Picturebook.where(:book => 'vacation').pluck(:img)[0] %>;
        $('#display_images').append("<img src='" + image + "' >");

    });

</script>

Aucun commentaire:

Enregistrer un commentaire