# I get Error after creating product

**URL:** <https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408>\
**Category:** Rails\
**Created:** [August 17, 2010, 8:35am UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408 "2010-08-17T08:35:02Z")\
**Posts on this page:** 8\
**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 17, 2010, 8:35am UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/1 "2010-08-17T08:35:02Z")

</div>

I get the following error inside my browser:  
ActiveRecord::RecordNotFound in ProductsController#show

Couldn’t find Product without an ID

RAILS\_ROOT: /Users/musdev/work/depot  
Application Trace | Framework Trace | Full Trace

/Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active\_record/base.rb:1567:in  
`find_from_ids' /Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in`find’  
/Users/musdev/work/depot/app/controllers/products\_controller.rb:17:in  
`show’

Request

Parameters:

{“id”=\>“2”}

The code on line 17 in my controller looks like this

def show  
@product = Product.find(params[:id =\> “show”])

```
respond_to do |format|
  format.html {render show.html.erb}
  format.xml #{ render :xml => @product }
end

```

end

I’m new to rails and i cannot pinpoint where my issue is occurring  
Can someone please give me a hand

Thank you

---

<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 17, 2010, 8:46am UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/2 "2010-08-17T08:46:15Z")

</div>

Musdev M. wrote:

> I get the following error inside my browser:  
> ActiveRecord::RecordNotFound in ProductsController#show
> 
> Couldn’t find Product without an ID

> Request
> 
> Parameters:
> 
> {“id”=\>“2”}
> 
> The code on line 17 in my controller looks like this
> 
> def show  
> @product = Product.find(params[:id =\> “show”])
> 
> ```
> respond_to do |format|
> format.html {render show.html.erb}
> format.xml #{ render :xml => @product }
> end
> 
> ```
> 
> end
> 
> I’m new to rails and i cannot pinpoint where my issue is occurring  
> Can someone please give me a hand
> 
> Thank you

Hi,  
Your code should be like this,  
def show  
@product = Product.find(params[:id])

```
 respond_to do |format|
   format.html {render show.html.erb}
   format.xml #{ render :xml => @product }
 end

```

end

Thanks,  
Anubhaw

---

<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 17, 2010, 1:47pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/3 "2010-08-17T13:47:19Z")

</div>

Anubhaw P. wrote:

> Musdev M. wrote:
> 
> > I get the following error inside my browser:  
> > ActiveRecord::RecordNotFound in ProductsController#show
> > 
> > Couldn’t find Product without an ID
> 
> > Request
> > 
> > Parameters:
> > 
> > {“id”=\>“2”}
> > 
> > The code on line 17 in my controller looks like this
> > 
> > def show  
> > @product = Product.find(params[:id =\> “show”])
> > 
> > ```
> > respond_to do |format|
> > format.html {render show.html.erb}
> > format.xml #{ render :xml => @product }
> > end
> > 
> > ```
> > 
> > end

> > I’m new to rails and i cannot pinpoint where my issue is occurring  
> > Can someone please give me a hand
> > 
> > Thank you
> 
> Hi,  
> Your code should be like this,  
> def show  
> @product = Product.find(params[:id])
> 
> ```
> respond_to do |format|
> format.html {render show.html.erb}
> format.xml #{ render :xml => @product }
> end
> 
> ```
> 
> end
> 
> Thanks,  
> Anubhaw

Hey Anubhaw,

Thank you, I tried that but now I get this error message:

SystemStackError in ProductsController#show

stack level too deep

RAILS\_ROOT: /Users/musdev/work/depot  
Application Trace | Framework Trace | Full Trace

/Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active\_record/base.rb:1689:in  
`[]' /Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1689:in`construct\_finder\_sql’  
/Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active\_record/base.rb:1548:in  
`find_every' /Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1583:in`find\_one’  
/Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active\_record/base.rb:1569:in  
`find_from_ids' /Users/musdev/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in`find’  
/Users/musdev/work/depot/app/controllers/products\_controller.rb:17:in  
`show' /Users/musdev/work/depot/app/controllers/products_controller.rb:20:in`show’  
/Users/musdev/work/depot/app/controllers/products\_controller.rb:19:in  
`show’

Here is what my controller code looks like:

class ProductsController \< ApplicationController

# GET /products

# GET /products.xml

def index  
@products = Product.new  
@products = Product.all

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @products }
end

```

end

# GET /products/1

# GET /products/1.xml

def show  
@products = Product.find(params[:id])

```
respond_to do |format|
  format.html {render show.html.erb}
  format.xml #{ render :xml => @product }
end

```

end

# GET /products/new

# GET /products/new.xml

def new  
@product = Product.new

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @product }
end

```

end

# GET /products/1/edit

def edit  
@product = Product.find(params[:id])  
end

# POST /products

# POST /products.xml

def create  
@product = Product.new(params[:product])

```
respond_to do |format|
  if @product.save
    flash[:notice] = 'Product was successfully created.'
    format.html { redirect_to(@product) }
    format.xml { render :xml => @product, :status => :created, 

```

:location =\> @product }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @product.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

# PUT /products/1

# PUT /products/1.xml

def update  
@product = Product.find(params[:id])

```
respond_to do |format|
  if @product.update_attributes(params[:product])
    flash[:notice] = 'Product was successfully updated.'
    format.html { redirect_to(@product) }
    format.xml { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml { render :xml => @product.errors, :status => 

```

:unprocessable\_entity }  
end  
end  
end

# DELETE /products/1

# DELETE /products/1.xml

def destroy  
@product = Product.find(params[:id])  
@product.destroy

```
respond_to do |format|
  format.html { redirect_to(products_url) }
  format.xml { head :ok }
end

```

end  
end

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 17, 2010, 2:00pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/4 "2010-08-17T14:00:00Z")

</div>

Hi,  
stack level too deep error is not due to code modifications.  
Taking a look at following article might solve your problem  
‘[Ruby: stack level too deep (SystemStackError) | Dalibor Nasevic](http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror)’.

The error is due to system stack level being less then required by  
application.

Thanks,  
Anubhaw

---

<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 17, 2010, 3:00pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/5 "2010-08-17T15:00:10Z")

</div>

Anubhaw P. wrote:

> Hi,  
> stack level too deep error is not due to code modifications.  
> Taking a look at following article might solve your problem  
> ‘[Ruby: stack level too deep (SystemStackError) | Dalibor Nasevic](http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror)’.
> 
> The error is due to system stack level being less then required by  
> application.
> 
> Thanks,  
> Anubhaw

I went to the link abov and followed the steps and still getting the  
same SYSTEM STACK ERROR. I wonder what could be causing this issue, Im  
running rails 2.3.8.

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 17, 2010, 7:48pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/6 "2010-08-17T19:48:18Z")

</div>

Ar Chron wrote:

> You don’t need to reference the show.html.erb in your controller…  
> template implementations have that “# show.html.erb” text as a reminder  
> of which view is invoked.
> 
> def show  
> @product = Product.find(params[:id])  
> respond\_to do |format|  
> format.html # show.html.erb  
> format.xml { render :xml =\> @product }  
> end  
> end
> 
> should be fine.
> 
> In your view, are you referencing a method on the model that may be  
> recursing indefinitely? I’ve seen instances of tht which will cause a  
> stack level too deep error… but yours seems to be related to the find  
> operation in the controller.
> 
> Have you migrated your Products table with fields? - I don’t know if a  
> column-less table would have this effect…, never tried it myself.

Thanks Chron,  
that solution resolved my issue, I dropped the reference to show.html  
and it worked perfect.  
SO if the method is the same name as the view, I should never reference  
that view in the controller inside the method definition?

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 17, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/7 "2010-08-17T20:44:05Z")

</div>

On Aug 17, 6:48 pm, Musdev M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks Chron,  
> that solution resolved my issue, I dropped the reference to show.html  
> and it worked perfect.  
> SO if the method is the same name as the view, I should never reference  
> that view in the controller inside the method definition?

It’s unnecessary but harmless. The problem here is that you wrote

render show.html.erb

rather than render ‘show’ or something like that - with the above  
rails thinks it needs to call the show method (and then call a method  
named html on that and so) so you end up recursing into your own  
action infinitely

Fred

---

<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 17, 2010, 3:32pm UTC](https://www.ruby-forum.com/t/i-get-error-after-creating-product/193408/8 "2010-08-17T15:32:06Z")

</div>

You don’t need to reference the show.html.erb in your controller…  
template implementations have that “# show.html.erb” text as a reminder  
of which view is invoked.

def show  
@product = Product.find(params[:id])  
respond\_to do |format|  
format.html # show.html.erb  
format.xml { render :xml =\> @product }  
end  
end

should be fine.

In your view, are you referencing a method on the model that may be  
recursing indefinitely? I’ve seen instances of tht which will cause a  
stack level too deep error… but yours seems to be related to the find  
operation in the controller.

Have you migrated your Products table with fields? - I don’t know if a  
column-less table would have this effect…, never tried it myself.
