Prashant Tiwari
2006-Mar-13 07:35 UTC
[Rails] undefined method `validates_presence_of'' for #<ProductsContr
Hi, I am trying to use method `validates_presence_of'' for validating my input fields on form . I m using it in my action class as follows:- ======================validates_presence_of(params[:product][:quantity]) ===================== But when I am running my application i m getting error like:- ========================undefined method `validates_presence_of'' for #<ProductsContr ======================== What is problem here?? Also I want to validate the field on my form (quantity) for its value less than 10. if value entared in quantity field in my form is less than 10 then it should check it & should give validation message on my view. How to do this???? Thanx. Prash -- Posted via http://www.ruby-forum.com/.
joey__
2006-Mar-13 07:43 UTC
[Rails] Re: undefined method `validates_presence_of'' for #<ProductsC
Prashant Tiwari wrote:> Hi, > > I am trying to use method `validates_presence_of'' for validating my > input fields on form . I m using it in my action class as follows:- > ======================> validates_presence_of(params[:product][:quantity]) > =====================> > But when I am running my application i m getting error like:- > ========================> undefined method `validates_presence_of'' for #<ProductsContr > ========================> > What is problem here?? > > Also I want to validate the field on my form (quantity) for its value > less than 10. if value entared in quantity field in my form is less than > 10 then it should check it & should give validation message on my view. > > How to do this???? > > Thanx. > PrashThis should go in the model. validates_presence_of :quantity This is about validating data, it should b in the model not controller. Joey http://www.feedreed.com -- Posted via http://www.ruby-forum.com/.
Prashant Tiwari
2006-Mar-13 08:04 UTC
[Rails] Re: undefined method `validates_presence_of'' for #<ProductsC
Hi joy, In which part of model should i write this ''validates_presence_of'' method. Currently my model is as follows:- =====================================class Product < ActiveRecord::Base attr_reader :products attr_reader :quantiti def add_product(product,quantity) products=Product.find(product.id) end end ====================================== In above model where should i write code for ''validates_presence_of'' method??// Thanx. Prash -- Posted via http://www.ruby-forum.com/.
Arpan
2006-Mar-13 08:49 UTC
[Rails] Re: undefined method `validates_presence_of'' for #<ProductsC
=====================================class Product < ActiveRecord::Base attr_reader :products attr_reader :quantiti validates_presence_of :quantity def add_product(product,quantity) products=Product.find(product.id) end end ====================================== That ought to do it. Arpan -- Posted via http://www.ruby-forum.com/.
Prashant Tiwari
2006-Mar-13 09:04 UTC
[Rails] Re: undefined method `validates_presence_of'' for #<ProductsC
Arpan wrote:> =====================================> class Product < ActiveRecord::Base > attr_reader :products > attr_reader :quantiti > > validates_presence_of :quantity > > def add_product(product,quantity) > products=Product.find(product.id) > end > end > ======================================> > That ought to do it. > ArpanI tried with the same thing as u told. But I am not getting any error message or something like textbox with coloured borders for the fields which were blank. My Database table name is ''products'' & contains a field named as ''demand'' with datatype varchar. My view contains 3 textboxes named "demand1","demand2","demand3". Now when I click on submit button on form it should check for form fields against ''validates_presence_of'' method. So I ve written in my model class as follows:- =============class Product < ActiveRecord::Base validates_presence_of :demand end =============== But I am not getting ay error message even if I insert blank value in textbox & blank value gets added into database. Where is problem???? Thanx. Prash -- Posted via http://www.ruby-forum.com/.