Tony Augustine
2010-Mar-26 03:47 UTC
file upload error(can''t convert Tempfile into String)
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 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lasse Bunk
2010-Mar-26 15:55 UTC
Re: file upload error(can''t convert Tempfile into String)
Hey Tony, You just need name = upload[''uploads''].original_filename instead of name = upload[''uploads''] /Lasse 2010/3/26 Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> 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 > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tony Augustine
2010-Mar-27 03:46 UTC
Re: file upload error(can''t convert Tempfile into String)
Lasse Bunk wrote:> Hey Tony, > > You just need > > name = upload[''uploads''].original_filename > > instead of > > name = upload[''uploads''] > > /Lasse > > 2010/3/26 Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>thanks a lot its working now -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.