Allow URL helpers to work with optional scopes

Backport of #18022.

Conflicts:
	actionpack/CHANGELOG.md