Explorar el Código

Added validation and fixed flash of unstylized content

Andrew Kane hace 9 años
padre
commit
62d35ef15e
Se han modificado 2 ficheros con 13 adiciones y 6 borrados
  1. 2 0
      app/models/blazer/check.rb
  2. 11 6
      app/views/blazer/checks/_form.html.erb

+ 2 - 0
app/models/blazer/check.rb

@@ -2,6 +2,8 @@ module Blazer
   class Check < ActiveRecord::Base
     belongs_to :blazer_query, class_name: "Blazer::Query"
 
+    validates :blazer_query_id, presence: true
+
     def update_state(rows, error)
       self.state =
         if error

+ 11 - 6
app/views/blazer/checks/_form.html.erb

@@ -1,8 +1,18 @@
 <p class="text-muted">Checks are designed to identify bad data. A check fails if there are any results.</p>
+
+<% if @check.errors.any? %>
+  <div class="alert alert-danger"><%= @check.errors.full_messages.first %></div>
+<% end %>
+
 <%= form_for @check do |f| %>
   <div class="form-group">
     <%= f.label :blazer_query_id, "Query" %>
-    <%= f.select :blazer_query_id, Blazer::Query.order(:name).map { |q| [q.name, q.id] } %>
+    <div class="hide">
+      <%= f.select :blazer_query_id, Blazer::Query.order(:name).map { |q| [q.name, q.id] }, {include_blank: true} %>
+    </div>
+    <script>
+      $("#check_blazer_query_id").selectize().parents(".hide").removeClass("hide");
+    </script>
   </div>
   <div class="form-group">
     <%= f.label :emails %>
@@ -16,8 +26,3 @@
     <%= f.submit "Save", class: "btn btn-success" %>
   </p>
 <% end %>
-
-<script>
-  $("#check_blazer_query_id").selectize();
-  $("#check_schedule").selectize({"allowEmptyOption": true});
-</script>