Reputation: 6653
I'm using carrierwave to upload an image, this works fine up to now.
What i want to do is show the preview of the file to be submitted on the form after having selected the image.
At the moment the code I have is showing the previous image.
<%= image_tag(@book.cover_url(:thumb)) if @book.cover_url %>
how do I show the selected image rather than the image already uploaded?
Upvotes: 3
Views: 821
Reputation: 2923
Try http://jasny.github.io/bootstrap/javascript/#fileinput
It has a nice solution for displaying the image without the upload.
Upvotes: 0
Reputation: 23648
You don't.
And that has nothing to do with Carrierwave but rather with the fact that the image is not yet sent to the server by your browser so no part of the Rails stack is coming into play here.
What you need is a way to access the image inside the <input type="file">
and display it to the user.
This is possible by using the FileAPI that is part of HTML5, but it's only supported in modern browsers (Webkit/Gecko), and the API is not completely finished yet so it's kind of a changing target.
I would suggest you look into tools like plupload to upload the image to the server without submitting the form and then displaying that through JavaScript.
Upvotes: 1