Module: ClientValidation::FormBuilder

Defined in:
lib/client_validations/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#client_validationsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/client_validations/form_builder.rb', line 3

def client_validations
  if object.new_record?
    form_id = "new_#{object.class.to_s.downcase}"
  else
    form_id = "edit_#{object.class.to_s.downcase}"
  end
  declarations, validations = ClientValidation.current_adapter.render_script(object)
  js = "    \#{declarations}\n    $('#\#{form_id}').validate({\n      rules: \#{validations[:rules].to_json},\n      messages: \#{validations[:messages].to_json}\n    });\n  EOF\n\n  html = template.content_tag(:script, js, :type => \"text/javascript\")\n  html.respond_to?(:html_safe!) ? html.html_safe! : html\nend\n"