You might find http://filer.io helpful. It''s a cloud file storage
service that integrates upload and download functionality seamlessly
in Rails apps.
(disclaimer: I work on Filer.io)
On 20 Май, 17:15, Roy <poddoja...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I was trying to upload a video.......but if I click upload button
> .....nothing happens...I was using the same codes whatever I used for
> uploading picture-
> codes in model
> class Picture < ActiveRecord::Base
> validates_format_of :content_type,
> with: /^video/,
> message: "--- you can only upload pictures"
>
> def uploaded_picture=(picture_field)
> self.name = base_part_of(picture_field.original_filename)
> self.content_type = picture_field.content_type.chomp
> self.data = picture_field.read
> end
>
> def base_part_of(file_name)
> File.basename(file_name).gsub(/[^\w._-]/, '''')
> end
> end
>
> codes in controller:
> class UploadController < ApplicationController
> def get
> @picture = Picture.new
> end
> # . . .
>
> def save
> @picture = Picture.new(params[:picture])
> if @picture.save
> redirect_to(action: ''show'', id: @picture.id)
> else
> render(action: :get)
> end
> end
>
> def show
> @picture = Picture.find(params[:id])
> end
>
> def picture
> @picture = Picture.find(params[:id])
> send_data(@picture.data,
> filename: @picture.name,
> type: @picture.content_type,
> disposition: "inline")
> end
> end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.