Skip to content

Instantly share code, notes, and snippets.

@davetapley
Created November 9, 2012 16:05
Show Gist options
  • Save davetapley/4046513 to your computer and use it in GitHub Desktop.
Save davetapley/4046513 to your computer and use it in GitHub Desktop.
# Normal has_many / belongs_to:
>> a = c.permitted_ips
=> []
# What we got back was just an Array:
>> a.class
=> Array
# Now build a new record:
>> c.permitted_ips.build :address => '123123'
=> #<PermittedIp id: nil, client_id: 14, description: nil, address: "123123", created_at: nil, updated_at: nil>
# All makes sense so far
# But now let's check `a` is still `[]`:
>> a
=> [#<PermittedIp id: nil, client_id: 14, description: nil, address: "123123", created_at: nil, updated_at: nil>]
# How has that happened? (`a` appears to have re-evaluated itself),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment