title: rails 4 URI domain bad argument
body: <p>I'm trying to write a simple validation to check if a user's domain name is valid. Here's the model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    require 'net/http'
    validate :domain_check
  
    def domain_check
      uri = URI(domain)
  
      request  = Net::HTTP.new uri.host
      response = request.request_head uri.path
  
      if response.code.to_i &gt; 400
          errors.add(:domain, "This doesn't appear to be an valid site.")
      end
    end
  end
  </code></pre>
  
  <p>This is based off the example in the Rails how to <a href="http://guides.rubyonrails.org/active_record_validations.html#custom-methods" rel="nofollow">here</a>. </p>
  
  <p>However this keeps throwing an error <code>bad argument (expected URI object or URI string)</code> about the line </p>
  
  <pre><code>uri = URI(domain)
  </code></pre>
  
  <p>I assume the <code>domain</code> variable is not getting to the function-- it seemed odd in the example in the Rails book that it didn't pass any variable, but the form vars are getting passed in correctly (I can see them in the debug info) and the form item <code>domain</code> is populated.</p>
  
  <p>How do I pass in the <code>domain</code> var correctly so this custom validation method will work?</p>