I've got some really weird stuff happening. In a view, I'm populating a collection like this:
<% foo_options = Bar.find(f.object.bar_id).supplier_contracts.collect(&:foo).uniq.compact : [] %>
This is a collection of ActiveRecord models.
EDIT: This happens in a form, so f.object
here refers to another ActiveRecord model instance.
If I try dereferencing the collection's elements like this on the next line:
<%= foo_options.first.inspect %>
a valid model object gets inspected. Now, if I change it to
<%= foo_options.first.id %>
I get an exception "Called id for nil, which would mistakenly be 4". If I change it to
<%= foo_options.first.try :id %>
everything's OK, it displays the object's ID. Why does the exception happen?