@card.submissions
returns this:
<ActiveRecord::Associations::CollectionProxy [#<Submission id: nil, user_id: nil, card_id: 7, created_at: nil, updated_at: nil, text: "">]>
@card.submissions.any?
returns true
.
@card.submissions.count
returns 0
.
What I'm looking to implement is:
if @card.submissions.any?
render @card.submissions
end
Looks like Submission is a new record (since id is nil). If it's new, it hasn't made it to the database yet. count
makes a SQL call to the database to determine the number of rows so is rightly returning zero. any?
is returning true since there is an object in the collection.
What happens if you try @card.submissions.to_a.size
(to ensure you load them from the database then check the size of the array).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With