Hi, I''m using file_column to do the image uploads .i want to know how to do the validation to upload only jpg or png or gif images. RIght now the user can upload any type of file.I want to restrict it only image type. i also want to know how to flash the error message in my view. Please 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-/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 -~----------~----~----~----~------~----~------~--~---
Hello,>Hi, >I''m using file_column to do the image uploads .i want to know how to do >the validation to upload only jpg or png or gif images.class Album < ActiveRecord::Base file_column :image validates_file_format_of :image, :in => ["gif", "jpg"] validates_filesize_of :image, :in => 1.kilobytes..5000.kilobytes end Good Luck, ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Reinhart Ariando YM : booking2heaven Web: 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 -~----------~----~----~----~------~----~------~--~---
> class Album < ActiveRecord::Base > file_column :image > > validates_file_format_of :image, :in => ["gif", "jpg"], :message => "Hey, Upload only GIF and JPG format" > validates_filesize_of :image, :in => 1.kilobytes..5000.kilobytes > > end >------------ in view ------------ <%= error_messages_for "image" %> Good Luck, ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Reinhart Ariando YM : booking2heaven Web: 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 -~----------~----~----~----~------~----~------~--~---
Visit Indonesia 2008 wrote:> >> class Album < ActiveRecord::Base >> file_column :image >> >> validates_file_format_of :image, :in => ["gif", "jpg"], :message => "Hey, Upload only GIF and JPG format" >> validates_filesize_of :image, :in => 1.kilobytes..5000.kilobytes >> >> end >> > > ------------ > in view > ------------ >Hi, I have a problem the validations are not happening in my model . i even tried validating somethgin else like validates_presence_of :comments where comments is a text field even this validation fails. Can u please 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi Koli, I don''t know how your app is structured, but have you put the validation rules into your photo model? I''ve got a similar app with both album and photo models. VI2008''s example puts such validation on an attribute of an album, rather than of a photo. Depends what your db looks like, really. Have you got any more details? Cheers, Josh On Feb 20, 11:52 am, Koli Koli <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Visit Indonesia 2008 wrote: > > >> class Album < ActiveRecord::Base > >> file_column :image > > >> validates_file_format_of :image, :in => ["gif", "jpg"], :message => "Hey, Upload only GIF and JPG format" > >> validates_filesize_of :image, :in => 1.kilobytes..5000.kilobytes > > >> end > > > ------------ > > in view > > ------------ > > Hi, > I have a problem the validations are not happening in my model . > i even tried validating somethgin else like > validates_presence_of :comments where comments is a text field > even this validation fails. > > Can u please help??? > -- > 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 -~----------~----~----~----~------~----~------~--~---
> > Hi, > I have a problem the validations are not happening in my model . > i even tried validating somethgin else like > validates_presence_of :comments where comments is a text field > even this validation fails. > > Can u please help???The validation in AR should work properly, as long as the column name in your table is correct, no matter of the type data is for validate_presence_of. if it is not working, you will have error message. If you want validate a field that is not from your table, you should add attr_reader :anyname or attr_accessor :anyname or in your AR you can validate using : #it is the same like attr_accessor def anyname=(new_name) if new_name.nil? errors.add("anyname", "is empty.") end end . yeah such as a josh said, Paste us more details. ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Reinhart Ariando YM : booking2heaven Web: 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 -~----------~----~----~----~------~----~------~--~---
> The validation in AR should work properly, as long as the column name in > your table is correct, no matter of the type data is for > validate_presence_of. if it is not working, you will have error message. > If you want validate a field that is not from your table, you should > add attr_reader :anyname or attr_accessor :anyname or in your AR you can > validate using :Hi, class Entry < ActiveRecord::Base has_many :problems belongs_to :reply require ''remote_uploads.rb'' file_column :image, :magick => { :versions => { "thumb" =>"50x50"} } validates_file_format_of :image, :in => ["gif", "jpg","png"], :message =>"must be a jpg,png or gif file type" validates_presence_of :comments end table structure: comments is a column in the entry table. in my view i have <%= error_messages for ''entry'' %> i hope the above info is sufficient. -- 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 -~----------~----~----~----~------~----~------~--~---
> in my view i have > > <%= error_messages for ''entry'' %> >the correct is <%= error_messages_for ''entry'' %> tell me if it works. -- 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 wrote:> >> in my view i have >> >> <%= error_messages for ''entry'' %> >> > > > the correct is <%= error_messages_for ''entry'' %> > > tell me if it works.Hi , It was syntax error while typing in the forum.it is as u have mentioned only. THe thing is . i''m doing a image upload to iframe using ajax. is that where the problem lies?? so when i hit the upload button it actually does not show the create action in the firebug . -- 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 -~----------~----~----~----~------~----~------~--~---