Skip to content

Conversation

@bellmyer
Copy link

@bellmyer bellmyer commented Jul 4, 2018

I've added an option, used like so:

validates :url, url: {ensure_protocol: true}

This updates the attribute with the protocol, when missing. This way, all urls can be saved in a valid format suitable for linking. It makes sense to "normalize" urls into their linkable format before saving, rather than checking them every time when used.

There may be a concern about a validator actually updating an attribute. I'll admit, it feels a little odd. But it also seems like the cleanest way to handle the problem. I don't want to reject urls that are only missing the protocol, but I don't want to allow them into the database without a protocol, either.

ALSO

Running the specs generated a failure for ".no" TLD's. It seems that certain words like "no" and "off", when not used in quotes, have special meanings in YAML. This was fixed by putting all protocols and zones in quotes, within domain.yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant