Guest User

Untitled

a guest
Jun 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def inline_error_block(object, method, prepend_text="", append_text="", css_class="form-error", &block)
  2. obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))
  3. errors = obj.errors.on(method.to_s) if obj
  4. inline_error_block_with_messages( errors, prepend_text, append_text, css_class, &block )
  5. end
  6.  
  7. # if you have an array of error messages rather than a model use this.
  8. def inline_error_block_with_messages( errors, prepend_text="", append_text="", css_class="form-error", &block )
  9. content = capture(&block)
  10. if errors and errors.any?
  11. concat(content_tag("div",
  12. content_tag("p", "#{prepend_text}#{errors.is_a?(Array) ? errors.first : errors}#{append_text}", :class => "generated-error") + content,
  13. :class => css_class
  14. ), block.binding)
  15. else
  16. concat(content, block.binding)
  17. end
  18. end
Add Comment
Please, Sign In to add comment