Hello all, How to give validation on a field which is not a database column. I mean i am having a file field(upload_resume) in my views. So i want to give validation on it that size should be less then 1mb. I tried self.upload_resume and params[:upload_resume] but both are not working. So guys, light me some directions. -- 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.
are you using any plug in for file field like attechment_fu or paperclip . if yes please type On Tue, Jul 20, 2010 at 3:37 PM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello all, > > How to give validation on a field which is not a database column. I mean > i am having a file field(upload_resume) in my views. So i want to give > validation on it that size should be less then 1mb. I tried > self.upload_resume and params[:upload_resume] but both are not working. > > So guys, light me some directions. > -- > 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. > >-- Thanks: Rajeev sharma -- 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.
kannav rajeev wrote:> are you using any plug in for file field like attechment_fu or > paperclip . if yes please typeNo i am not using any thing.> > On Tue, Jul 20, 2010 at 3:37 PM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> >> -- >> 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. >> >> > > > > -- > Thanks: > Rajeev sharma-- 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.
Virtual attributes in your model? not sure if I understand your problem as I''ve never done file uploads with Rails. def my_non_db_field ## do something end On 20 July 2010 14:20, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> kannav rajeev wrote: > > are you using any plug in for file field like attechment_fu or > > paperclip . if yes please type > > No i am not using any thing. > > > > > On Tue, Jul 20, 2010 at 3:37 PM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > wrote: > >> > >> -- > >> 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. > >> > >> > > > > > > > > -- > > Thanks: > > Rajeev sharma > > -- > 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.
On 20 July 2010 11:07, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello all, > > How to give validation on a field which is not a database column. I mean > i am having a file field(upload_resume) in my views. So i want to give > validation on it that size should be less then 1mb. I tried > self.upload_resume and params[:upload_resume] but both are not working.Are you trying to check the file size before or after the upload? Colin -- 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.
Colin Law wrote:> On 20 July 2010 11:07, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hello all, >> >> How to give validation on a field which is not a database column. I mean >> i am having a file field(upload_resume) in my views. So i want to give >> validation on it that size should be less then 1mb. I tried >> self.upload_resume and params[:upload_resume] but both are not working. > > Are you trying to check the file size before or after the upload?Hello Guys, Thanks for your replies. Yes i want to check the size of file before upload only. I mean first i am checking that file had valid attributes or not. If it has then upload it else dont. Currenly i am doing this in controllers but for cleaner code i want to do it in models with validations.> > Colin-- 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.
On 20 July 2010 14:32, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 20 July 2010 11:07, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Hello all, >>> >>> How to give validation on a field which is not a database column. I mean >>> i am having a file field(upload_resume) in my views. So i want to give >>> validation on it that size should be less then 1mb. I tried >>> self.upload_resume and params[:upload_resume] but both are not working. >> >> Are you trying to check the file size before or after the upload? > > Hello Guys, > Thanks for your replies. > > Yes i want to check the size of file before upload only. I mean first i > am checking that file had valid attributes or not. If it has then upload > it else dont. > Currenly i am doing this in controllers but for cleaner code i want to > do it in models with validations.How are you checking the file attributes in the controller? Colin> > >> >> Colin > > -- > 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. > >-- 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.
Colin Law wrote:> On 20 July 2010 14:32, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> Hello Guys, >> Thanks for your replies. >> >> Yes i want to check the size of file before upload only. I mean first i >> am checking that file had valid attributes or not. If it has then upload >> it else dont. >> Currenly i am doing this in controllers but for cleaner code i want to >> do it in models with validations. > > How are you checking the file attributes in the controller?Just like as if File.size(params[:upload_resume]) > 1mb redirect_to :back with some flash[:notice] end The only problem with this is that i am unable to retain the form values after redirecting.> > Colin-- 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.
On 20 July 2010 14:54, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 20 July 2010 14:32, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >>> Hello Guys, >>> Thanks for your replies. >>> >>> Yes i want to check the size of file before upload only. I mean first i >>> am checking that file had valid attributes or not. If it has then upload >>> it else dont. >>> Currenly i am doing this in controllers but for cleaner code i want to >>> do it in models with validations. >> >> How are you checking the file attributes in the controller? > > Just like as > if File.size(params[:upload_resume]) > 1mb > redirect_to :back with some flash[:notice] > endIs params[:upload_resume] a filename on the users PC? I am probably showing my ignorance here, but how does the server know the size of a file on the users PC? I hope you are not testing this by ''uploading'' from a PC which is actually also the server running the rails app, so that the file is directly accessible from the rails app before it is uploaded. Colin> > The only problem with this is that i am unable to retain the form values > after redirecting. > > >> >> Colin > > -- > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 20 July 2010 14:54, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> do it in models with validations. >>> >>> How are you checking the file attributes in the controller? >> >> Just like as >> if File.size(params[:upload_resume]) > 1mb >> �redirect_to :back with some flash[:notice] >> end > > Is params[:upload_resume] a filename on the users PC? I am probably > showing my ignorance here, but how does the server know the size of a > file on the users PC? I hope you are not testing this by ''uploading'' > from a PC which is actually also the server running the rails app, so > that the file is directly accessible from the rails app before it is > uploaded.Hello Colin, Thanks to you guys for you replies. Somehow i managed to do this. I created a virtual method to solve this.> > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.