Guest User

Untitled

a guest
May 7th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment