Skip to content

Instantly share code, notes, and snippets.

class Upload < ActiveRecord::Base
has_attached_file :uploaded_file
validates_presence_of :uploaded_file
end
def self.list_all_files
find(:all, :order => "created_at DESC")
end
end
<% form_for @mp3, :url => uploads_path, :html => { :multipart => true, :method => :post } do |f| %>
<%= error_messages_for :mp3 %>
<p>
<%= f.file_field :mp3 %>
</p>
<p>
<%= f.submit "Upload" %>
</p>
map.resources :uploads
class UploadsController &lt; ApplicationController
def new
@mp3 = Mp3.new
end
def create
@mp3 = Mp3.new(params[:mp3])
if @mp3.save
redirect_to upload_path(@mp3)
else
class Mp3 < ActiveRecord::Base
# attach an mp3 via Paperclip, then validate it
has_attached_file :mp3