Business intelligence made simple
Fixed form errors with Turbolinks
Andrew Kane1b0b079637a4
diff --git a/app/assets/javascripts/blazer/application.js b/app/assets/javascripts/blazer/application.jsindex 30fb1282..0d8a2d78 100644--- a/app/assets/javascripts/blazer/application.js+++ b/app/assets/javascripts/blazer/application.js@@ -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);diff --git a/app/controllers/blazer/base_controller.rb b/app/controllers/blazer/base_controller.rbindex c0bd02fe..6790c4df 100644--- a/app/controllers/blazer/base_controller.rb+++ b/app/controllers/blazer/base_controller.rb@@ -81,6 +81,11 @@ module Blazerendhelper_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.rbdef redirect_to(url = {}, options = {})diff --git a/app/controllers/blazer/checks_controller.rb b/app/controllers/blazer/checks_controller.rbindex bcd57c9f..ed475dca 100644--- a/app/controllers/blazer/checks_controller.rb+++ b/app/controllers/blazer/checks_controller.rb@@ -21,7 +21,7 @@ module Blazerif @check.saveredirect_to query_path(@check.query)else- render :new+ render_errors @checkendend@@ -29,7 +29,7 @@ module Blazerif @check.update(check_params)redirect_to query_path(@check.query)else- render :edit+ render_errors @checkendenddiff --git a/app/controllers/blazer/dashboards_controller.rb b/app/controllers/blazer/dashboards_controller.rbindex c8e6336b..5785f301 100644--- a/app/controllers/blazer/dashboards_controller.rb+++ b/app/controllers/blazer/dashboards_controller.rb@@ -19,7 +19,7 @@ module Blazerif update_dashboard(@dashboard)redirect_to dashboard_path(@dashboard)else- render :new+ render_errors @dashboardendend@@ -49,7 +49,7 @@ module Blazerif update_dashboard(@dashboard)redirect_to dashboard_path(@dashboard, variable_params)else- render :edit+ render_errors @dashboardendenddiff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 92affcf7..b671441a 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -45,7 +45,7 @@ module Blazerif @query.saveredirect_to query_path(@query, variable_params)else- render :new+ render_errors @queryendend@@ -158,7 +158,7 @@ module Blazerif @query.errors.empty? && @query.update(query_params)redirect_to query_path(@query, variable_params)else- render :edit+ render_errors @queryendenddiff --git a/app/views/blazer/_errors.html.erb b/app/views/blazer/_errors.html.erbnew file mode 100644index 00000000..95618ae4--- /dev/null+++ b/app/views/blazer/_errors.html.erb@@ -0,0 +1,3 @@+<% if @errors.any? %>+ <div class="alert alert-danger"><%= @errors.full_messages.first %></div>+<% end %>diff --git a/app/views/blazer/checks/_form.html.erb b/app/views/blazer/checks/_form.html.erbindex 093f9d95..ba41889b 100644--- a/app/views/blazer/checks/_form.html.erb+++ b/app/views/blazer/checks/_form.html.erb@@ -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">diff --git a/app/views/blazer/dashboards/_form.html.erb b/app/views/blazer/dashboards/_form.html.erbindex 8039effd..514825c5 100644--- a/app/views/blazer/dashboards/_form.html.erb+++ b/app/views/blazer/dashboards/_form.html.erb@@ -1,6 +1,4 @@-<% if @dashboard.errors.any? %>- <div class="alert alert-danger"><%= @dashboard.errors.full_messages.first %></div>-<% end %>+<div id="errors"></div><%= form_for @dashboard, url: (@dashboard.persisted? ? dashboard_path(@dashboard, variable_params) : dashboards_path(variable_params)), remote: true do |f| %><div class="form-group">diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erbindex ea024fbf..ee2effd2 100644--- a/app/views/blazer/queries/_form.html.erb+++ b/app/views/blazer/queries/_form.html.erb@@ -1,6 +1,4 @@-<% if @query.errors.any? %>- <div class="alert alert-danger"><%= @query.errors.full_messages.first %></div>-<% end %>+<div id="errors"></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">