Sha256: 776914e9015d951a9370385c6c63eb4da45dc3d49ac6a5c3ad8a6425c8eed11e

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module TwiceBaked::ApplicationHelper

  def tb_form_errors(record)
    if record.errors.any?
      content_tag :div, :class => 'form-errors' do
        concat(tb_form_error_header(record))
        concat(raw "<ul>")
        concat(raw record.errors.full_messages.collect{ |msg| "<li>#{msg}</li>" }.join())
        concat(raw "</ul>")
      end
    end
  end

  def tb_form_error_header(record)
    if record.errors.any?
      message = "Please correct the following #{'error'.pluralize(record.errors.size)}:"
      return content_tag :h4, message, :class => 'form-field-error'
    end
  end

  def tb_form_error_field(record, attribute)
    message = record.errors[attribute].first
    if message
      return content_tag :p, message, :class => 'help-block form-field-error'
    end
  end

  def tb_form_field(attribute)
    content_tag :div, :class => 'form-group' do
      concat label_tag attribute, attribute, :class => 'col-sm-2 control-label'
      concat(content_tag(:div, :class => 'col-sm-10') do
        text_field_tag attribute, :placeholder => attribute, :class => 'form-control'
      end)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_core-1.3.0 app/helpers/twice_baked/application_helper.rb
tb_core-1.3.0.beta2 app/helpers/twice_baked/application_helper.rb
tb_core-1.3.0.beta1 app/helpers/twice_baked/application_helper.rb