# Issue with validation

**URL:** <https://www.ruby-forum.com/t/issue-with-validation/57289>\
**Category:** Rails\
**Created:** [April 9, 2006, 1:34am UTC](https://www.ruby-forum.com/t/issue-with-validation/57289 "2006-04-09T01:34:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [April 9, 2006, 1:34am UTC](https://www.ruby-forum.com/t/issue-with-validation/57289/1 "2006-04-09T01:34:14Z")

</div>

Hello, I just got hold of the book ‘Agile Web D. with Rails’  
and I have been following along.  
I just went through a segment of trying to add validation to a form.

I added the following code, as instructed, to my app/models/Products.rb  
file:

protected  
def validate  
errors.add(:Price, “should be positive”) unless Price.nil? || Price

> = 0.01  
> end

with the exception of the upper-case P on Price, this is letter for  
letter (unless I just can’t read today).

When I try and submit the form I get this error.

NameError in Admin#create

uninitialized constant Price

Can’ figure this out at all. I’ve been following the tutorial to the  
letter and I’m sure if they had had this problem it would have been  
mentioned. Anyone have any ideas? I’m using the latest release of RoR,  
Mac OSX and MySQL 4.1

Thanks

---

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [April 9, 2006, 2:10am UTC](https://www.ruby-forum.com/t/issue-with-validation/57289/2 "2006-04-09T02:10:19Z")

</div>

Thanks, Clint,

Issue resolved, it did work as typed once I switched the var to  
lower-case. I must have skipped over that part.

---

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [April 9, 2006, 1:43am UTC](https://www.ruby-forum.com/t/issue-with-validation/57289/3 "2006-04-09T01:43:36Z")

</div>

On 4/8/06, Jason W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> protected  
> def validate  
> errors.add(:Price, “should be positive”) unless Price.nil? || Price \>=  
> 0.01  
> end
> 
> with the exception of the upper-case P on Price, this is letter for letter  
> (unless I just can’t read today).

Uppercase words are considered constants or class names. lower case  
‘price’  
would be a local variable, you probably want to use ‘@price’ (note the  
lower  
case too) since that would be an instance variable.

So I’d try:

protected  
def validate  
errors.add(:price, “should be positive”) unless @price.nil? ||  
@price \>=  
0.01  
end

I’m still just a noob though so take my advice with a grain of salt.

-Clint
