Hey folks,
I was wondering what would be the best approach for this situation.
In my application layout I’ve got a partial which shows the user’s cart
if
there is any.
- if @cart && !@cart.line_items.empty? %h1 Your Cart = render @cart
However, if I want to, for instance, click on the button to show me this
particular product details (/product/22), a NilException is thrown as I
would’ve lost @cart object on the request.
I managed to fix it by adding this piece of code to the product’s
controller:
before_action :load_current_cart, only: [:show]
def load_current_cart
- @cart = current_cart**end*
Is there a better/clean way to do it?
Thanks in advance