I have a few questions relating to a Transaction object that I’m creating.
Transaction belongs_to Loan and Loan has_many Transactions.
Therefore, I setup a nested route:
resources :loans do
resources :transactions
end
My question is: How do I pass the loan value into the Transaction’s ‘loan_id’ field? Is this best done in the controller or as a hidden_field in the form? Does the nested route create an easy way to grab this variable?
I assumed this would be done automatically, but the field is empty when I saved it as-is.
Any help would be greatly appreciated!
if you call a specific transaction, the route for a
newtransaction will beyou could use model association like this: in your
createaction:that way your new
@transactionwill be already populated with the loan_id