Scanning text to find domain types

I'm trying to piece together a part of a create action in a controller that scans the the text entered and intelligently understands what type of domain name it is.

I have a text box called "domain_names". A user puts domains into the box separated by commas, e.g. ","

In the controller it hits it like this:

@extracted_domains = (params[:domain_names]).split(",")
@extracted_domains.each do |domain|
    domain_scan = domain.scan(/(\w+)[.]/).flatten
    com_scan = domain.scan(/[.](\w+)/).flatten
    new_domain_type = DomainType.find_or_create_by_domain_type(:domain_type => com_scan)
    new_domain = Domain.create(:domain => domain_scan, :domain_type_id =>

In the console it works great. But when I put it into practise I get really odd things stored in the database. For example if :domain was meant to have the value "google", it will instead have the value "---\n- google\n" , when its stored in the database.

No idea why

Thanks in advance.


Problem: It was putting an array into a string.

Solution: Make it a string.

domain_scan = domain.scan(/(\w+)[.]/).flatten.first
com_scan = domain.scan(/[.](\w+)/).flatten.first


As for your issue, can we see the exact params that are sent?

I would take a look at for domain extraction.

It appears to be fed YAML input. Three dashes at the beginning of the string followed by a newline are a strong indicator of YAML:

Need Your Help

Stay on same page after button click event

javascript sharepoint sharepoint-2010

We use a survey link for feedback A suffix is use after the URL to make sure all SP components are not seen. When suffix is used there is a cancel button at the bottom which needs to be hidden or r...