class Tutorial < ApplicationRecord
belongs_to :user
has_attached_file
end
Create migration
$ rails generate paperclip tutorial image
class AddAttachmentImageToTutorials < ActiveRecord::Migration
def self.up
change_table :tutorials do |t|
t.attachment :image
end
end
def self.down
remove_attachment :tutorials, :image
end
end
https://www.youtube.com/watch?v=Z5W-Y3aROVE
https://github.com/thoughtbot/paperclip
Add Image Magic
sudo apt-get install imagemagick -y
Add to Gemfile
gem 'paperclip', '~> 4.3', '>= 4.3.6'
Add to
app/model/tutorial.rb
Create migration
$
rails generate paperclip tutorial image
$
rails generate paperclip tutorial tryruby_image terminal_image trygit_image htmlcss_image
$
rake db:migrate