Dhaval Phansalkar
2008-Apr-18 11:29 UTC
attachment_fu strange behaviour with file uploading
Hi, thr''s a strange behavior with attachment_fu. when i upload a file, sometimes it gets uploaded without prb/error msg and sometimes the same file gives the error as size error msg. particularly, when i upload the next file immediately after another. can anybody help me in this? thanks in advance... this is my mugshots model:- class Mugshot < ActiveRecord::Base has_attachment :content_type => [''application/vnd.ms-excel''], :storage => :file_system, :max_size => 5.megabytes, :path_prefix=>''public/temp_files'' # validates_as_attachment def validate errors.add_to_base("You must choose a file to upload") unless self.filename unless self.filename == nil # Images should only be GIF, JPEG, or PNG [:content_type].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add_to_base("You can only upload .xls file") end end # Images should be less than 5 MB [:size].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add_to_base("file size should be smaller than 5 MB in size") end end end end end -Dhaval -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Visit Indonesia 2008
2008-Apr-18 11:48 UTC
Re: attachment_fu strange behaviour with file uploading
I prefer to hack attachment_fu.rb in vendor/plugin/attachment_fu/lib than make def validate in model. But here''s my correction for you : class Mugshot < ActiveRecord::Base has_attachment :content_type => [''application/vnd.ms-excel''], :storage => :file_system, :size => 0.megabyte..5.megabytes, :path_prefix=>''public/temp_files'' validates_as_attachment end NOW, go to {RAILS_ROOT}\vendor\plugins\attachment_fu\attachment_fu.rb in line 405 : ... def attachment_attributes_valid? [:size, :content_type].each do |attr_name| enum = attachment_options[attr_name] errors.add attr_name, ActiveRecord::Errors.add_to_base("You can only upload .xls file")unless enum.nil? || enum.include?(send(attr_name)) end end ... and refresh your server. What do you think? Reinhart http://teapoci.blogspot.com -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dhaval Phansalkar
2008-Apr-18 12:14 UTC
Re: attachment_fu strange behaviour with file uploading
hi Reinhart, hey, that worked!!! though "errors.add attr_name, ActiveRecord::Errors.add_to_base("You can only upload .xls file")unless enum.nil? || enum.include?(send(attr_name))" gave me NoMethod error, so i kept the default line back. that gave me default error msg for wrong upload. but that worked. and even if i put ":size => 0.megabyte..5.megabytes," line in my code, that also worked fine :) now i could upload the files continuously... without error :D Thanks a ton Reinhart -Dhaval -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---