Hello, help me figure it out. Trying to create a basket in the view wrote:

<%= button_to 'Добавить в корзину', line_items_path(item_id: item) %> 

in line_item_controller:

 @cart = current_cart item = Item.find(params[:item_id]) @line_item = @cart.line_items.build(item: item) 

I get the error:

 undefined local variable or method `item' for #<#<Class:0x00000004f509c0>:0x00000004f5fb78> 

I tried to register the same code in item_controller, then I get:

 Couldn't find Item without an ID 

UPD: I tried to do as in the book "Agile development", it is written there that way, if I declare variables as a member of the object, nothing changes, the errors are the same ...

    1 answer 1

    In order for variables to be available in views, they must be declared as members of the object:

     @item = Item.find(params[:item_id]) @line_item = @cart.line_items.build(item: @item) 

    and

     <%= button_to 'Добавить в корзину', line_items_path(item_id: @item) %> 
    • I tried to do as in the book "Agile development", it says there that way, if I declare that as a member of the object nothing changes, the errors are the same ... - Metallicolis