Skip to content

Instantly share code, notes, and snippets.

@ivalkeen
Created May 25, 2012 19:34
Show Gist options
  • Save ivalkeen/2790062 to your computer and use it in GitHub Desktop.
Save ivalkeen/2790062 to your computer and use it in GitHub Desktop.
Blog: Multiple files upload with paperclip
class AttachedAsset < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
has_attached_file :asset, :styles => { :large => "800x800", :medium => "400x400>", :small => "200x200>" }
attr_accessible :asset, :asset_file_name
end
class Item < ActiveRecord::Base
has_many :attached_assets, :as => :attachable
accepts_nested_attributes_for :attached_assets, :allow_destroy => true
attr_accessible :title, :description, :attached_assets_attributes
end
class ItemsController < ApplicationController
def create
@item = Item.new(params[:item])
if @item.save
redirect_to action: "index"
else
render "new"
end
end
end
= simple_form_for(@item, html: { multipart: true }) do |f|
= f.input :title
= f.input :description
= file_field_tag('item_attached_assets_asset', multiple: true, name: "item[attached_assets_attributes][][asset]")
= f.button :submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment