Agile Web Dev on Rails - ActiveRecord::RecordNotFound Prob

Hi there

I’ve also made a start on the Agile Web Dev using Rails book! I’ve been
hit with a problem when hitting the ‘Add to Cart’ button - I get the
following error message:

ActiveRecord::RecordNotFound in StoreController#add_to_cart
Couldn’t find Product without an ID
RAILS_ROOT: ./script/…/config/…

Application Trace | Framework Trace | Full Trace
D:/Ruby/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:939:in
find_from_ids' D:/Ruby/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:382:infind’
#{RAILS_ROOT}/app/controllers/store_controller.rb:11:in `add_to_cart’

It seems to me that the id of the item is not been passed in - my
storecontroller code looks like this:

add a product to the cart

def add_to_cart

@cart = find_cart
@product = Product.find(params[:id])
@cart.add_product(@product)

end

It’s not obvious to me where the id is supposed to be set / got from?
Can anybody help?

Thanks,
Dave

davet wrote:

It’s not obvious to me where the id is supposed to be set / got from?
Can anybody help?

Oops!! Found it!! The button code in my index.rhtml page was missing ‘,
:id => product %>’…

Anyways, thanks for the help!! :slight_smile:

davet wrote:

Application Trace | Framework Trace | Full Trace
def add_to_cart
Thanks,
Dave

Dave,

Does your app/views/store/index.html file have the “:id => product” as
mentioned in the book? (Pg 113 of the PDF)

Cheers
Mohit.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs