Search code examples
ruby-on-railsactivemerchant

How do I show the values of deeply nested fields?


I have a tables of Users, Carts, Orders and OrderTransactions.

My schema looks like:

  • User has one cart
  • Cart has one order
  • Order has many transactions

I would like to display the user_id in the order transaction partial.

I can display the cart_id with <%= order_transaction.order.cart_id %>

So I thought that <%= order_transaction.order.cart.user_id %> would work but it's giving a "undefined method `user_id' for nil:NilClass" error.

What am I missing here? Any help would be much appreciated!


Solution

  • Just noticed, It does actually work. I needed to delete all transactions created before the changes I made.