Module: Safai::DeviseHelpers

Defined in:
lib/safai.rb

Overview

Instance Method Summary collapse

Instance Method Details

#devise_error_messages!Object

DEVISE end



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/safai.rb', line 98

def devise_error_messages!
  flash_alerts = []
  error_key = 'errors.messages.not_saved'

  if !flash.empty?
    flash_alerts.push(flash[:error]) if flash[:error]
    flash_alerts.push(flash[:alert]) if flash[:alert]
    flash_alerts.push(flash[:notice]) if flash[:notice]
    error_key = 'devise.failure.invalid'
  end

  return "" if resource.errors.empty? && flash_alerts.empty?
  errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages

  messages = errors.map { |msg| (:li, msg) }.join
  sentence = I18n.t(error_key, :count    => errors.count,
                               :resource => resource.class.model_name.human.downcase)

  html = <<-HTML
  <div id="error_explanation">
    <h2>#{sentence}</h2>
    <ul>#{messages}</ul>
  </div>
  HTML

  html.html_safe
end

#devise_mappingObject



92
93
94
# File 'lib/safai.rb', line 92

def devise_mapping
  @devise_mapping ||= Devise.mappings[:user]
end

#resourceObject



88
89
90
# File 'lib/safai.rb', line 88

def resource
  @resource ||= User.new
end

#resource_nameObject



84
85
86
# File 'lib/safai.rb', line 84

def resource_name
  :user
end