Reputation: 21
I'm trying to upload images through carrier wave, and using rails.
using minimagick.
Actually, the uploads working properly I think, but images are not shown up.
Also it shows nil
value in database.
here's my code.
class User < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
<input type="file" name='image'>
def edit_complete
user = User.find(session[:user_id])
user.image = params[:image]
user.save
redirect_to :back
end
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
No errors appeared, but nothing saved in database.
I expect image files should be saved in public/upload
folder, and image file should be shown in database in rails c
User.all
.
However, when I upload 1.png file,
there are nothing saved, and public/upload folder is not generated.
Also in database shows nil
value.
Is there any solution for this?
Upvotes: 2
Views: 2225
Reputation: 135
Try something like this:
<%= form_for @user, :html => {:multipart => true} do |f| %>
<%= f.file_field :image%>
<%= f.submit 'Edit'%>
<% end %>
Upvotes: 1
Reputation: 77
In file upload You need to use multipart option in form tag ie multipart option should be true in form tag.
Upvotes: 2