diff --git a/app/controllers/body_trackers_controller.rb b/app/controllers/body_trackers_controller.rb index 6cd622b..2c45243 100644 --- a/app/controllers/body_trackers_controller.rb +++ b/app/controllers/body_trackers_controller.rb @@ -9,6 +9,8 @@ class BodyTrackersController < ApplicationController end def defaults + failed_objects = [] + # Units available_units = @project.units.pluck(:shortname, :id).to_h defaults = Unit.where(project: nil).map do |u| @@ -38,7 +40,11 @@ class BodyTrackersController < ApplicationController attrs['formula_attributes']['unit_id'] = available_units[q.formula.unit.shortname] end obj = @project.quantities.create(attrs) - available_quantities[[q.name, q.domain]] = obj if obj.persisted? + if obj.persisted? + available_quantities[[q.name, q.domain]] = obj + else + failed_objects << obj + end end end @@ -62,6 +68,13 @@ class BodyTrackersController < ApplicationController flash[:notice] += " and #{new_sources.length > 0 ? new_sources.length : "no" } new" \ " #{'source'.pluralize(new_sources.length)}" + if failed_objects.present? + flash[:notice] += " (loading #{failed_objects.length} objects failed, see errors)" + flash[:error] = failed_objects.map do |o| + "
#{o.class.name} #{o.name}: #{o.errors.full_messages.join(', ')}
" + end.join.html_safe + end + redirect_to :back end end diff --git a/app/models/quantity.rb b/app/models/quantity.rb index 1224801..11840d7 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -44,6 +44,7 @@ class Quantity < ActiveRecord::Base end end + # TODO: move as an association extension module def self.filter(project, filters) quantities = all diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e0f630..fa29439 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,11 +47,11 @@ en: formula: attributes: code: - disallowed_syntax: 'cannot be parsed: %{syntax}' - disallowed_token: 'includes disallowed token: "%{token}"' - disallowed_keyword: 'includes disallowed keyword: "%{keyword}"' - disallowed_method: 'includes disallowed method call: "%{method}"' - unknown_dependency: 'contains undefined dependency: %{identifier}' + disallowed_syntax: 'cannot be parsed "%{syntax}"' + disallowed_token: 'includes disallowed token "%{token}"' + disallowed_keyword: 'includes disallowed keyword "%{keyword}"' + disallowed_method: 'includes disallowed method call "%{method}"' + unknown_dependency: 'contains undefined dependency "%{identifier}"' computation_failed: 'computation failed for "%{quantity}": %{description} (%{count} values missing)' body_trackers: