lib/joosy/forms.rb in joosy-0.1.0.RC1 vs lib/joosy/forms.rb in joosy-0.1.0.RC2

- old
+ new

@@ -7,26 +7,16 @@ module InstanceMethods def joosy_store(entity, data=nil, &block) if entity.save joosy_succeed(data, entity, &block) else - joosy_fail(entity.errors.messages, entity.class.name) + joosy_fail(entity.errors, entity.class.name) end end def joosy_fail(errors, entity=false) errors = Hash[*errors.map {|x| [x, nil]}.flatten] if errors.is_a?(Array) - - if !entity - notifications = errors - else - notifications = {} - errors.each do |k, v| - notifications["#{entity.underscore}[#{k}]"] = v - end - end - - joosy_respond notifications, :unprocessable_entity + joosy_respond errors, :unprocessable_entity end def joosy_succeed(data, entity=nil, &block) block.call(entity) if block_given? joosy_respond (data.is_a?(Proc) ? data.call(entity) : (data || entity))