hi. I use attachment_fu for uploading avatars. I only want to save the attachment, if the height and the width of the image are smaller than 100px.(the system should not resize it) If the attachment is larger I want to show a error message. Here is my the model. --------------------------------------------------- class Avatar < ActiveRecord::Base belongs_to :user has_attachment :content_type => :image, :storage => :file_system, :max_size => 300.kilobytes validates_as_attachment end --------------------------------------------------- thanks for your help. xinu -- 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 -~----------~----~----~----~------~----~------~--~---
I think the best way is to resize image without error confirmation. Simple add: :resize_to => [50,50] to the has_attachment. Or if you really want to check size, then you may use validate method, and check for the if width > your_width_max and height > your_height_max Look into this article: http://www.marklunds.com/articles/one/312 On Jul 28, 1:08 pm, "Michael M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi. > > I use attachment_fu for uploading avatars. > I only want to save the attachment, if the height and the width of the > image are smaller than 100px.(the system should not resize it) If the > attachment is larger I want to show a error message. > > Here is my the model. > --------------------------------------------------- > class Avatar < ActiveRecord::Base > belongs_to :user > has_attachment :content_type => :image, > :storage => :file_system, > :max_size => 300.kilobytes > > validates_as_attachment > > end > --------------------------------------------------- > > thanks for your help. > xinu > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
thank you Solid! -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks for what, what was the solution... I still don''t see any way to find out the dimensions of the original image, nor can I find information anywhere about how to get the original dimensions, just using "width" doesn''t work. On Jul 28, 5:27 am, "Michael M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> thank you Solid! > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---