Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using background jobs to upload files
- @file = File.new(params[:file])
- respond_to do |format|
- if @file.save
- format.html { redirect_to @file, notice: 'file was successfully uploaded.' }
- format.json { render json: @file, status: :created, location: @file }
- format.js
- else
- format.html { render action: "new" }
- format.json { render json: @file.errors, status: :unprocessable_entity }
- format.js
- end
- end
- end
- has_attached_file :file,
- :path => ":rails_root/public/system/:attachment/:id/:style/:normalized_file_file_name",
- :url => "/system/:attachment/:id/:style/:normalized_file_file_name"
- validates_attachment_content_type :file, :content_type => ['audio/mp3', 'audio/mpeg', 'audio/mid', 'audio/x-wav']
- Paperclip.interpolates :normalized_file_file_name do |attachment, style|
- attachment.instance.normalized_file_file_name
- end
- def normalized_mp3_file_name
- "#{self.mp3_file_name.gsub( /[^a-zA-Z0-9_.]/, ' ')}"
- end
Advertisement
Add Comment
Please, Sign In to add comment