I'm using bootstrap3 and a particular plugin for bootstrap called file-input. I'm using file-input and paperclip to attach a picture of a restaurant to my Restaurant model.
One of the things I would like to do is have the ability for my users, when editing a restaurant image, to be able to see the old restaurant image (which is stored in @restaurant.image.url). After reading the documentation, I found that I can set a default image to file-input by passing in a source like so:
initialPreview: [
"<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>",
"<img src='/images/jellyfish.jpg' class='file-preview-image' alt='Jelly Fish' title='Jelly Fish'>",
],
What I'm stuck on is how do I get my @restaurant.image.url into the src attribute of a javascript array, that I can then pass on into the file-input plugin.
I found this question and it made it seem like if I turn my restaurant.js file into a restaurant.js.erb file I can just use ruby expressions.
javascript
("#image_upload").fileinput( initialPreview: ["<img src='<%= @restaurant.image.url %>' class='file-preview-image'>",]);
But @restaurant is blank in my javascript file. Anyone know why?
I am using rails 4, I don't know if that is the difference.