Anubhaw Prakash wrote:
Musdev Musdev 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