Module: InsteddRails::InsteddAppHelper

Defined in:
app/helpers/instedd_rails/instedd_app_helper.rb

Instance Method Summary collapse

Instance Method Details

#errors_for(object, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/instedd_rails/instedd_app_helper.rb', line 23

def errors_for(object, options = {})
  unless object.nil?
    if object.errors.any?
       # TODO change on rails 3.1 to ActiveModel::Naming.param_key(object)
      object_name = options[:as].try(:to_s) || ActiveModel::Naming.singular(object)

       :div, :class => "box error_description #{options[:class] || 'w60'}" do
        ( :h2 do
          t("errors_prohibited_being_saved", default: "%{errors_count} prohibited this %{object_name} from being saved:") % {errors_count: pluralize(object.errors.count, 'error'), object_name: object_name.humanize}
        end) \
        + \
        ( :ul do
          raw object.errors.full_messages.map { |msg| (:li, msg) }.join
        end)
      end
    end
  end
end

#flash_messageObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/instedd_rails/instedd_app_helper.rb', line 3

def flash_message
  res = nil

  keys = { :notice => 'flash_notice', :error => 'flash_error', :alert => 'flash_error' }

  keys.each do |key, value|
    if flash[key]
      html_option = { :class => "flash #{value}" }
      html_option[:'data-hide-timeout'] = 3000 if key == :notice
      res =  :div, html_option do
         :div do
          flash[key]
        end
      end
    end
  end

  res
end