Reputation: 441
I am using Carrierwave so that a user can upload an image. I am making a blog website. I have no errors but the image is not appearing. I want the image to appear in the post VIEW. Here is my code:
Post.rb
mount_uploader :image, ImageUploader
Posts _form.html.erb
<div>
<%= form_for @post do |f|%>
<%= f.label :image %>
<%= f.file_field :image %>
</div>
image_uploader.rb
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
Posts show.html.erb
<strong>Image:</strong>
<%= image_tag @post.image_url%>
</p>
When I run my application and view a post it just says Image: with no image underneath it.
UPDATE:
I installed ImageMagick/GraphicsMagick, and when I go to save post it says:
1 error prohibited this post from being saved:
Image Failed to manipulate with MiniMagick, maybe it is not an image? `Original Error: ImageMagick/GraphicsMagick is not installed`
and underneath it displays the image but it wont save the post.
Upvotes: 1
Views: 1063
Reputation: 11000
While form_for sets encoding multipart automatically, but in my projects I still define it. Try this:
<%= form_for(@post, hmtl: { multipart: true } ) do |f| %>
Upvotes: 1