Skip to main content

Posts

Showing posts with the label CarrierWave gem

Simple Image and File Upload using Ruby on Rails (CarrierWave gem)

I’m going to show you a very simple way to upload your attachments or a picture using CarrierWave gem. Steps: 1.    Open Terminal. 2.   Create a new project terminal > rails new imageupload 3.   Add this line to Gemfile     gem ‘ carrierwave ‘ 4.   terminal > bundle install 5.   terminal > rails g uploader image 6.   terminal > rails g scaffold Painting name:string image:string 7.   terminal > rake db:migrate 8.   Add this line to painting.rb (app/models/painting.rb)     class Painting < ActiveRecord::Base      mount_uploader :image, ImageUploader     end 9.   And then in your app/views/paintings/_form.html.erb edit your code, which become     <%= f.label :image %>     <%= f. text_field :image %>   ...