Model Validations + Urgent

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.

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 B. [email protected]
wrote:


You received this message because you are subscribed to the Google G. “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

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 11:07, Hemant B. [email protected] 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

Colin L. wrote:

On 20 July 2010 11:07, Hemant B. [email protected] 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 G.s,
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

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 B. [email protected]
wrote:


You received this message because you are subscribed to the Google G. “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

On 20 July 2010 14:32, Hemant B. [email protected] wrote:

Hello G.s,
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 L. wrote:

On 20 July 2010 14:32, Hemant B. [email protected] wrote:

Hello G.s,
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

Colin L. wrote:

On 20 July 2010 14:54, Hemant B. [email protected] 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

On 20 July 2010 14:54, Hemant B. [email protected] 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.

Colin