views:

769

answers:

2

Hi

I have this line of code:

<%= link_to "Add to cart", :controller => "car", :action => "add_to_cart", :car => car %>

when im in the add_to_cart method...how can i call the :car please?

@car = Car.new(params[:car])

doesnt work because it says im trying to stringify

I dont understand whats wrong because I used this to create new users and it worked fine.

By the way, car is my car object.

thnx

A: 

You probably don't want to pass the car object as a parameter, try just passing car.id. What do you get when you inspect(params) after clicking "Add to cart"?

bensie
the problem with that is that I don't have these cars saved anywhere since I'm scraping the informatin from the web and am not storing them anywhere..thus the id is non-existent as yet and apart from that would be useless :/
Lily
Once again, what do you get when you inspect(params)?
bensie
params[:product].inspect came back empty ""
Lily
params[:car].inspect sry
Lily
if you don't have an 'id' what do you expect to become a parameter?
Dmytrii Nagirniak
+2  A: 

Maybe try this:

<%= link_to "Add to cart", 
            :controller => "car", 
            :action => "add_to_cart", 
            :car => car.attributes %>

But I'd really like to see where the car object is getting setup for this page (i.e., the rest of the view).

MattMcKnight