<commit_before>module ClientValidation
  module FormBuilder
    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 = <<-EOF
        #{declarations}
        $('##{form_id}').validate({
          rules: #{validations[:rules].to_json},
          messages: #{validations[:messages].to_json}
        });
      EOF

      html = template.content_tag(:script, js, :type => "text/javascript")
      html.respond_to?(:html_safe!) ? html.html_safe! : html
    end
  end
end<commit_msg>fixed bug when object is not new<commit_after>module ClientValidation
  module FormBuilder
    def client_validations
      if object.new_record?
        form_id = "new_#{object.class.to_s.downcase}"
      else
        form_id = "edit_#{object.class.to_s.downcase}_#{object.to_param}"
      end
      declarations, validations = ClientValidation.current_adapter.render_script(object)
      js = <<-EOF
        #{declarations}
        $('##{form_id}').validate({
          rules: #{validations[:rules].to_json},
          messages: #{validations[:messages].to_json}
        });
      EOF

      template ||= @template

      html = template.content_tag(:script, js, :type => "text/javascript")
      html.respond_to?(:html_safe!) ? html.html_safe! : html
    end
  end
end
{'fraction_non_alphanumeric': 0.12890094979647218, 'fraction_numerical': 0.0, 'mean_word_length': 2.8411458333333335, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '396009', 'n_tokens_mistral': 454, 'n_tokens_neox': 457, 'n_words': 81}