Module: Integrity::Helpers::Forms

Included in:
Integrity::Helpers
Defined in:
lib/integrity/helpers/forms.rb

Instance Method Summary collapse

Instance Method Details

#checkbox(name, condition, extras = {}) ⇒ Object



13
14
15
16
17
# File 'lib/integrity/helpers/forms.rb', line 13

def checkbox(name, condition, extras={})
  attrs = { :name => name, :type => "checkbox", :value => "1" }
  attrs[:checked] = !!condition
  attrs.update(extras)
end

#error_class(object, field) ⇒ Object



9
10
11
# File 'lib/integrity/helpers/forms.rb', line 9

def error_class(object, field)
  object.errors.on(field).nil? ? "" : "with_errors"
end

#errors_on(object, field) ⇒ Object



4
5
6
7
# File 'lib/integrity/helpers/forms.rb', line 4

def errors_on(object, field)
  return "" unless errors = object.errors.on(field)
  errors.map {|e| e.gsub(/#{field} /i, "") }.join(", ")
end

#notifier_form(notifier) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/integrity/helpers/forms.rb', line 19

def notifier_form(notifier)
  haml(notifier.to_haml, :layout => :notifier, :locals => {
    :config => current_project.config_for(notifier),
    :notifier => "#{notifier.to_s.split(/::/).last}",
    :enabled => current_project.notifies?(notifier)
  })
end