i tried a method to implementa file uploader by using amethod below
this is ma controlller method to upload
def save_imports
Contactslist.save(params[:list])
render :text => “File uploaded successfully”
this is ma view file
.remote
-
form_for(@list, :url=> save_imports_list_path(@list, :format =>
“js”), :html => { :multipart => true, :target => “uploading”, :onsubmit
=> “$('list_submit).disabled = true” }) do |f|
= link_to_close edit_list_path(@list)
.section
%small
#{t :add_contacts_from_file}
%table{ :width => 500, :cellpadding => 0, :cellspacing => 0 }
%tr
%td{ :valign => :top }
.label.top.req #{t :upload_new}:
=f.file_field :uploads, :style => “width:240px”.buttonbar
= f.submit “#{t:save_contacts}”, :onclick => “this.disabled =
true”
#{t :or}
= link_to_cancel edit_list_path(@list)
i created amodel contact list and nclude amethod as given below
class Contactslist < ActiveRecord::Base
def self.save(upload)
name = upload[‘uploads’]
puts name
directory = “public/avatars”
# create the file path
path = File.join(directory, name)
# write the file
File.open(path, “wb”) { |f| f.write(upload[‘uploads’].read) }
end
end
when i tried to upload a file its showing errors as
TypeError in ListsController#save_imports
can’t convert Tempfile into String
can anyone help.is there any fault in this method?actually i wanted
toupload this files into a table callled contactslists or to move to
a folder in my application pls provide help