Salam..

Untuk mengupload/menyimpan file image/foto ke mysql saya menggunakan sintak..:

Controller:

def create
    @pelajar = Pelajar.new(params[:pelajar])
      respond_to do |format|
      pelajar.save
      format.html { redirect_to(@pelajar) }    
end


def code_image
        @image_data = Pelajar.find(params[:id])
        @image = @image_data.binary_data
        send_data(@image, :type => @image_data.content_type, :namafail => 
@image_data.namafail, :disposition => 'inline')
end

Model:

def image_file=(input_data)
        self.namafail = input_data.original_filename
        self.content_type = input_data.content_type.chomp
        self.binary_data = input_data.read
end


View:

<% form_for(:pelajar, @pelajar, :url => {:action=>'create'}, :html=> 
{:multipart=>true}) do |f| %>

Fotor :<%= f.file_field :image_file  %>

<%= f.submit "Simpan"%>

Sedangkan Untuk menampilkan foto tersebut saya gunakan sintax:

<%= image_tag("/pelajars/code_image/#...@pelajar.id}", :alt => "Image") %>


Nah, Kalo kita ingin menyimpan file seperti: pdf,doc,ppt dll Apakah sama sintax 
seperti tersebut diatas...?
Terus gimana caranya supaya kita bisa mendowload file2 yang tersimpan 
tersebut...?


Mohon pencerahan...ya...:)


Thanks...

Zen


      

[Non-text portions of this message have been removed]

Reply via email to