@@ -37,6 +37,10 @@ $(document).on("click", "#code", function () {
$(this).toggleClass("expanded");
});
+$(document).on("ajax:error", "form", function(e, data, status, xhr) {
+ $("#errors").replaceWith(data.responseText);
+});
+
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
@@ -81,6 +81,11 @@ module Blazer
end
helper_method :blazer_user
+ def render_errors(resource)
+ @errors = resource.errors
+ render partial: "blazer/errors", status: :unprocessable_entity
+ end
# from turbolinks
# https://github.com/turbolinks/turbolinks-rails/blob/master/lib/turbolinks/redirection.rb
def redirect_to(url = {}, options = {})
@@ -21,7 +21,7 @@ module Blazer
if @check.save
redirect_to query_path(@check.query)
else
- render :new
+ render_errors @check
@@ -29,7 +29,7 @@ module Blazer
if @check.update(check_params)
- render :edit
@@ -19,7 +19,7 @@ module Blazer
if update_dashboard(@dashboard)
redirect_to dashboard_path(@dashboard)
+ render_errors @dashboard
@@ -49,7 +49,7 @@ module Blazer
redirect_to dashboard_path(@dashboard, variable_params)
@@ -45,7 +45,7 @@ module Blazer
if @query.save
redirect_to query_path(@query, variable_params)
+ render_errors @query
@@ -158,7 +158,7 @@ module Blazer
if @query.errors.empty? && @query.update(query_params)
@@ -0,0 +1,3 @@
+<% if @errors.any? %>
+ <div class="alert alert-danger"><%= @errors.full_messages.first %></div>
+<% end %>
@@ -2,9 +2,7 @@
<p class="text-muted">Checks are designed to identify bad data. A check fails if there are any results.</p>
<% end %>
-<% if @check.errors.any? %>
- <div class="alert alert-danger"><%= @check.errors.full_messages.first %></div>
-<% end %>
+<div id="errors"></div>
<%= form_for @check, remote: true do |f| %>
<div class="form-group">
@@ -1,6 +1,4 @@
-<% if @dashboard.errors.any? %>
- <div class="alert alert-danger"><%= @dashboard.errors.full_messages.first %></div>
<%= form_for @dashboard, url: (@dashboard.persisted? ? dashboard_path(@dashboard, variable_params) : dashboards_path(variable_params)), remote: true do |f| %>
-<% if @query.errors.any? %>
- <div class="alert alert-danger"><%= @query.errors.full_messages.first %></div>
<%= form_for @query, url: (@query.persisted? ? query_path(@query, variable_params) : queries_path(variable_params)), html: {class: "the_form", autocomplete: "off"}, remote: true do |f| %>
<div class="row">