Skip to content

Commit

Permalink
Multiple object support for form error tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed May 13, 2010
1 parent 201258f commit 1737601
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/controllers/paragraph_feature.rb
Expand Up @@ -840,12 +840,22 @@ def define_form_error_tag(name,options={})
end

define_tag name do |tag|
frm = tag.locals.send(frm_obj)
if frm && frm.object && frm.object.errors && frm.object.errors.length > 0
if block_given?
objs = yield tag
objs = [ objs ] unless objs.is_a?(Array)
else
frm = tag.locals.send(frm_obj)
objs = [ frm.object ] if frm && frm.object
end
objs ||= []
objs = objs.compact
error_count = objs.inject(0) { |acc,obj| acc + obj.errors.length }
if error_count > 0
messages = objs.inject([]) { |acc,obj| acc + obj.errors.full_messages }.join(tag.attr['separator'] || "<br/>")
if tag.single?
frm.object.errors.full_messages.join(tag.attr['separator'] || "<br/>")
messages
else
tag.locals.value = frm.object.errors.full_messages.join(tag.attr['separator'] || "<br/>")
tag.locals.value = messages
tag.expand
end
else
Expand Down

0 comments on commit 1737601

Please sign in to comment.