Polymorphic Association in Rails
1. Generate Scaffold of Product rails g scaffold Product title:string description:text + rake db:migrate 2. Generate Scaffold of Review rails g scaffold Review title:string + rake db:migrate 3 rails g model Picture imageable_id:integer imageable_type:string image:string + rake db:migrate 4. Add Gemfile gem 'carrierwave' -- in Gemfile + bundle 5. Add Uploader File $ rails generate uploader Avatar 6. Add code in the Picture Model :: class Picture < ApplicationRecord belongs_to :imageable, polymorphic: true mount_uploader :image, AvatarUploader end 7. Add code in the Product Model :: class Product < ApplicationRecord has_many :pictures, as: :imageable end 8 Add code in the Review Model :: class Review < ApplicationRecord has_many :pictures, as: :imageable end 9. Add code in app/views.products/ form.html.erb :: <div class="field"> <%= form.label :image %> <%= form.file_field :image, multiple: t...