I would change your code to match what’s in the book. IN this case, you need to keep the views/orders/new.html.erb
template and have the button in app/views/_cart.html.erb
configured to trigger the new_order_path
.
What you have in app/views/_cart.html.erb
is using the cart show path:
<%= button_to "Continue to Secure Checkout", cart, method: :get %>
The second argument is a Cart
and the third argument (method: :get
) says to use an HTTP GET. Rails combines these two pieces of information and will trigger /carts/«card.id»
, which will call CartsController
’s show
method, and params[:id]
will be the value of card.id
The book says to do this:
<%= button_to 'Checkout', new_order_path, method: :get %>
This is a bit of a weird Rails thing, but in this case, the second argument is not an Active Record, but is a string returned by the method new_order_parth
. That method returns /orders/new
.
If you do bin/rails routes
on the command line, you will see a bunch of stuff around orders. You should see a line that indicates the new
action on the OrdersController
. It may be confusing because Rails sometimes will say orders
in place of OrdersController
.
But, at any rate, clicking the button above (that goes to new_order_path
) will trigger the OrdersController
’s new
method. And that will render the view in app/views/orders/new.html.erb
. That view calls render 'form'
which will render app/views/orders/_form.html.erb
and insert that into the view.
LMK if this makes sense - Rails has a lot of implicit/conventional behavior that can get confusing, especially because sometimes if you don’t get it 100% right, Rails won’t give you an error but just acts weird.