Module: RailsUjsForm::Helper

Defined in:
lib/rails-ujs-form/helper.rb

Instance Method Summary collapse

Instance Method Details

#render_errors(builder) ⇒ Object

not sure why there isn’t something like this in rails

render the errors on an object in a fairly standard way:

<ul class=“errors”>

<li data-for="name">Name cannot be blank</li>

</ul>



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails-ujs-form/helper.rb', line 10

def render_errors(builder)
  errors = builder.object.errors
  messages = errors.full_messages
   :ul, :class => :errors do
    output = ''
    errors.each_with_index do |error, i|
      output << (:li, :'data-for' => "#{builder.object_name}_#{error[0]}") { messages[i] }
    end
    output.html_safe
  end
end