# Getting Error in browser

**URL:** <https://www.ruby-forum.com/t/getting-error-in-browser/192698>\
**Category:** Rails\
**Created:** [August 4, 2010, 9:00am UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698 "2010-08-04T09:00:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 4, 2010, 9:00am UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/1 "2010-08-04T09:00:27Z")

</div>

I get this Error message in my browser  
SyntaxError in ProductsController#index

/Users/musdev/work/depot/app/models/product.rb:11: Invalid char `\x1B’  
in expression

The code in my product.rb file

class Product \< ActiveRecord::Base  
validates\_presence\_of :title, :description, :image\_url  
validates\_numericality\_of :price  
validate :price\_must\_be\_at\_least\_a\_cent  
validates\_uniqueness\_of :title  
validates\_format\_of :image\_url,  
:with =\> %r{.(gif|jpg|png)$}i,  
:message =\> ‘must be URL for GIF, JPG’ +  
‘or PNG image.’  
eend  
def self.find\_products\_for\_sale  
find(:all, :order =\> “title”)  
end

def price\_must\_be\_at\_least\_a\_cent  
errors.add(:price, ‘should be at least 0.01’) if price.nil? ||  
price \< 0.01  
end

what does this mean? I dont see anything on that line

Regards

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 4, 2010, 9:48am UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/2 "2010-08-04T09:48:42Z")

</div>

Check out ProductsController # index  
also please  
On Wed, Aug 4, 2010 at 12:30 PM, Musdev M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## validates\_presence\_of :title, :description, :image\_url end
> 
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
Thanks:  
Rajeev sharma

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 4, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/3 "2010-08-04T16:02:18Z")

</div>

On Wed, Aug 4, 2010 at 03:00, Musdev M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I get this Error message in my browser  
> SyntaxError in ProductsController#index
> 
> /Users/musdev/work/depot/app/models/product.rb:11: Invalid char `\x1B’  
> in expression
> 
> The code in my product.rb file

Which of those lines is #11? I don’t see immediately any obvious bad  
chars in what you posted, but perhaps that’s due in part to the email  
processing. Have you tried deleting and retyping that line?

-Dave

–  
Specialization is for insects. -RAH | Have Pun, Will Babble! -me  
Programming Blog: [http://codosaur.us](http://codosaur.us) | Work: [http://davearonson.com](http://davearonson.com)  
Leadership Blog: [http://dare2xl.com](http://dare2xl.com) | Play: [http://davearonson.net](http://davearonson.net)

- 
  - 
    - 
      - 
        - WATCH THIS SPACE \* \* \* \* \* | Ruby: [http://mars.groupsite.com](http://mars.groupsite.com)

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 4, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/4 "2010-08-04T18:06:01Z")

</div>

Dave A. wrote:

> On Wed, Aug 4, 2010 at 03:00, Musdev M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > I get this Error message in my browser  
> > ï¿½SyntaxError in ProductsController#index
> > 
> > /Users/musdev/work/depot/app/models/product.rb:11: Invalid char `\x1B’  
> > in expression
> > 
> > The code in my product.rb file
> 
> Which of those lines is #11? I don’t see immediately any obvious bad  
> chars in what you posted, but perhaps that’s due in part to the email  
> processing. Have you tried deleting and retyping that line?
> 
> -Dave
> 
> –  
> Specialization is for insects. -RAH ï¿½| Have Pun, Will Babble! -me  
> Programming Blog: [http://codosaur.us](http://codosaur.us) | Work: [http://davearonson.com](http://davearonson.com)  
> Leadership Blog: ï¿½[http://dare2xl.com](http://dare2xl.com) | Play: [http://davearonson.net](http://davearonson.net)
> 
> - 
> - 
> - 
> - 
> - WATCH THIS SPACE \* \* \* \* \* | Ruby: [http://mars.groupsite.com](http://mars.groupsite.com)

I tried deleting and retyping the line without touching anything else  
and now I see this error message in my browser

NoMethodError in Products#index

Showing app/views/products/index.html.erb where line #6 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each

Extracted source (around line #6):

3:  
4:

  
5:  
6: \<% @products.each do |product| %\>  
7:   
8: 

|   
9: \<%= image\_tag product.image\_url, :class =\> ‘list-image’ %\>

 |

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 5, 2010, 9:00am UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/5 "2010-08-05T09:00:46Z")

</div>

Ar Chron wrote:

> Musdev M. wrote:
> 
> > Showing app/views/products/index.html.erb where line #6 raised:
> > 
> > You have a nil object when you didn’t expect it!  
> > You might have expected an instance of Array.  
> > The error occurred while evaluating nil.each
> > 
> > Extracted source (around line #6):
> > 
> > 3:  
> > 4:
> > 
> >   
> > 5:  
> > 6: \<% @products.each do |product| %\>
> > 
> > Seems pretty obvious… @products is nil. That issue is in your  
> > controller.
> > 
> > lol thanks, I was about to take the sucker way out and start over, but  
> > how will I ever learn. I just created a new Product.new object in my  
> > controller and stored it in @products.
> > 
> > Thanks

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [August 4, 2010, 6:59pm UTC](https://www.ruby-forum.com/t/getting-error-in-browser/192698/6 "2010-08-04T18:59:59Z")

</div>

Musdev M. wrote:

> Showing app/views/products/index.html.erb where line #6 raised:
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.each
> 
> Extracted source (around line #6):
> 
> 3:  
> 4:
> 
>   
> 5:  
> 6: \<% @products.each do |product| %\>
> 
> Seems pretty obvious… @products is nil. That issue is in your  
> controller.
