Class: ClientSideValidations::Middleware::Url

Inherits:
Base
  • Object
show all
Defined in:
lib/custom_validations/client_side_validations_midleware/url.rb

Defined Under Namespace

Classes: URLAsHostValidationClass, URLValidationClass

Instance Method Summary collapse

Instance Method Details

#responseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/custom_validations/client_side_validations_midleware/url.rb', line 16

def response

  if request.params[:as_host] == 'true'
    obj = URLAsHostValidationClass.new
  else
    obj = URLValidationClass.new
  end

  obj.url = request.params[:value]
  obj.valid?

  if obj.errors.has_key? :url
    self.status = 400
    self.body = {message: obj.errors[:url].first}.to_json
  else
    self.status = 200
    self.body = 'true'
  end

  super
end