In this blog we see how to add image in our rails application
rails g uploader image( image replace any name)
Gem file add following gem
GemFile
gem "rmagick"
gem "carrierwave"
in your model for example your user model
model/user.rb
class user < ActiveRecord::Base
attr_accessible : :name, :user_image
mount_uploader :user_image, ImageUploader
end
and
app/uploaders/image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [200, 200]
end
end
Show.html.erb
<%= image_tag painting.user_image_url(:thumb) if painting.image? %>
insert.htm.erb
<%= f.file_field :user_image %>
No comments:
Post a Comment