Hello! I have 2 questions concerning attachment_fu. 1. Is it possible to validate dimensions of uploaded photo, i want it to accept only certain dimensions. 2. If i create for example :big_picture => ''800x600'' and :thumb => ''150x150>'' is it possible to delete the source, big image. -- 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 -~----------~----~----~----~------~----~------~--~---
On 18 Aug 2007, at 17:20, Pawel Jur wrote:> 1. Is it possible to validate dimensions of uploaded photo, i want > it to > accept only certain dimensions.Don''t force a user to upload files with certain dimensions, scale the image yourself (see 2.)> 2. If i create for example :big_picture => ''800x600'' and :thumb => > ''150x150>'' is it possible to delete the source, big image.Use :resize_to to resize the main image, this will "delete" the source image the user uploaded. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 quick reply!> > Don''t force a user to upload files with certain dimensions, scale the > image yourself (see 2.)That''s true. But what if it has to be a specially cropped image, it can''t be resized automaticlly as far as i know. It''s more for an admin than for a user but still it would be nice to have this kind of validation.>> 2. If i create for example :big_picture => ''800x600'' and :thumb => >> ''150x150>'' is it possible to delete the source, big image. > > Use :resize_to to resize the main image, this will "delete" the > source image the user uploaded. >thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
On 18 Aug 2007, at 18:10, Pawel Jur wrote:>> Don''t force a user to upload files with certain dimensions, scale the >> image yourself (see 2.) > > That''s true. But what if it has to be a specially cropped image, it > can''t be resized automaticlly as far as i know. It''s more for an admin > than for a user but still it would be nice to have this kind of > validation.attachment_fu has callbacks to handle this kind of thing yourself, you''d have to look them up in the api. You could also use these to do a scale (so the image fills up the dimensions) and then crop to the exact size you''re looking for. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 am having a hard time saving the uploaded files to the directory of my choice. There is the method full_filename() that is said to be the one to override to specify a custom path, but when I do so the file is not saved [code] #Here is the original method in the file_system_backend.rb file # Overwrite this method in your model to customize the filename. # The optional thumbnail argument will output the thumbnail''s filename. def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))) end [/code] I created a custom full_filename method in my Picture class, which was called on to generate the file name for the uploaded file, but when this method was used the file was not saved in the directory that I specified. Here is the updated method within the Picture class [code] def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, "pictures", thumbnail_name_for(thumbnail)) end [/code] I admit I am a little confused on how this method overrides the the one in the file_system_backend.rb file (I will have to read up on this), but for starters I just want to figure out why the files are not saving. There is also an issue in the thumbnails not being created. Sometimes they are created as they should be, then after testing things at a later time, they are no longer saved. The last thing that I am wondering about, is what is the common way to relate the images/files. I would think just to create an additional foreign key column in the table relating back to the parent table, but if that is the case I would have to create a couple of methods in the parent class, in this case Member, to retrieve a list of the thumbnails. That just seems like to much extra code for ruby, so I am thinking that there may already be something that is provided that will do this. Thanks for the help. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/24/07, chris <olsen.chris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am having a hard time saving the uploaded files to the directory of > my choice.attachment_fu has a :path_prefix => "/path/to/attachments/directory" option which allows you to set the directory of the uploaded files. I can''t remember off hand if it allows you to store them in a directory anywhere on the file system, it may require the directory to be under /public..> There is also an issue in the thumbnails not being created. Sometimes > they are created as they should be, then after testing things at a > later time, they are no longer saved.I''ve never had inconsistencies in saving thumbnails.. For me they either save or they don''t..> The last thing that I am wondering about, is what is the common way to > relate the images/files. I would think just to create an additional > foreign key column in the table relating back to the parent table, but > if that is the case I would have to create a couple of methods in the > parent class, in this case Member, to retrieve a list of the > thumbnails. That just seems like to much extra code for ruby, so I am > thinking that there may already be something that is provided that > will do this.I use single table inheritance with a different class for each image type, which specifies varying dimensions for each image. A better way of doing it is to use the polymorphic associations, although the restriction of doing it this way is that you must specify all the different image dimensions in one file, so you may get some superfluous image resizes that you don''t necessarily need (ie if you need an image size of 64x64 pixels for a Product and an image of 128x128 for an Article, you''ll get both sizes for each object, rather than a single image for a product and a single one for an Article). If you''re interested in the polymorphic way, you should definitely check out this sample application: http://blog.caboo.se/articles/2007/4/11/sample-rails-application Adam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---