I am creating an app which has a model "Gallery". I am having another model which is "GalleryPhoto". The relationship is: Gallery has_many GalleryPhoto
and GalleryPhoto belongs_to Gallery
.
Following are the models i have created:
class Gallery < ActiveRecord::Base
has_many :gallery_photos, dependent: :destroy
end
class GalleryPhoto < ActiveRecord::Base
belongs_to :gallery
has_attached_file :photo
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/jpg', 'image/png']
end
Now after i am creating the Gallery, on its index page i am having the link to add photos that will open a page to add photos. On this page i will be able to add photos using paperclip.
This is my new.html.erb for gallery_photo:
<%= form_for @gallery_photo,html: { multipart: true},url: gallery_photos_path,method: :post do |f| %>
<%= f.hidden_field :gallery_id, value: params[:gallery_id]%>
<%=f.file_field :photo%>
<%= f.submit "Start Upload",class: "btn btn-primary actions"%>
<% end %>
I am able to Upload single photo. But i am not getting how to upload multiple photos using paperclip. Any help will me appreciated.