Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def inline_error_block(object, method, prepend_text="", append_text="", css_class="form-error", &block)
- obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))
- errors = obj.errors.on(method.to_s) if obj
- inline_error_block_with_messages( errors, prepend_text, append_text, css_class, &block )
- end
- # if you have an array of error messages rather than a model use this.
- def inline_error_block_with_messages( errors, prepend_text="", append_text="", css_class="form-error", &block )
- content = capture(&block)
- if errors and errors.any?
- concat(content_tag("div",
- content_tag("p", "#{prepend_text}#{errors.is_a?(Array) ? errors.first : errors}#{append_text}", :class => "generated-error") + content,
- :class => css_class
- ), block.binding)
- else
- concat(content, block.binding)
- end
- end
Add Comment
Please, Sign In to add comment