lib/joosy/forms.rb in joosy-0.1.0.RC3 vs lib/joosy/forms.rb in joosy-0.1.0.alpha

- old
+ new

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