Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Using background jobs to upload files
  2. @file = File.new(params[:file])
  3.       respond_to do |format|
  4.       if @file.save
  5.         format.html { redirect_to @file, notice: 'file was successfully uploaded.' }
  6.         format.json { render json: @file, status: :created, location: @file }
  7.         format.js
  8.       else
  9.         format.html { render action: "new" }
  10.         format.json { render json: @file.errors, status: :unprocessable_entity }
  11.         format.js
  12.       end
  13.     end
  14. end
  15.        
  16. has_attached_file :file,
  17.     :path => ":rails_root/public/system/:attachment/:id/:style/:normalized_file_file_name",
  18.     :url => "/system/:attachment/:id/:style/:normalized_file_file_name"
  19.   validates_attachment_content_type :file, :content_type => ['audio/mp3', 'audio/mpeg', 'audio/mid', 'audio/x-wav']
  20.  
  21.   Paperclip.interpolates :normalized_file_file_name do |attachment, style|
  22.     attachment.instance.normalized_file_file_name
  23.   end
  24.  
  25.   def normalized_mp3_file_name
  26.     "#{self.mp3_file_name.gsub( /[^a-zA-Z0-9_.]/, ' ')}"
  27.   end