Rails `link_to` with a new ActiveRecord-object takes you to the index page

link_to with a persisted object takes us to the show page of the corresponding object:

@team = Team.first
link_to 'Cancel', @team
# => <a href="/teams/123">Cancel</a>

Today I learned that if the object is a new_record? the created link takes us to the index page of given Model:

@team = Team.new
link_to 'Cancel', @team
# => <a href="/teams">Cancel</a>

This is super handy for a “Cancel” button in a form, that usually should behave differently if the object is or is not persisted.